{"id":26528944,"url":"https://github.com/i2bskn/passwd","last_synced_at":"2025-03-21T16:19:31.866Z","repository":{"id":8158620,"uuid":"9579784","full_name":"i2bskn/passwd","owner":"i2bskn","description":"Passwd is provide hashed password creation and authentication.","archived":false,"fork":false,"pushed_at":"2021-03-19T08:31:52.000Z","size":144,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-19T16:39:01.189Z","etag":null,"topics":["authentication","password","rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/i2bskn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-21T13:30:27.000Z","updated_at":"2021-03-22T02:37:50.000Z","dependencies_parsed_at":"2022-09-14T13:31:29.351Z","dependency_job_id":null,"html_url":"https://github.com/i2bskn/passwd","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i2bskn%2Fpasswd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i2bskn%2Fpasswd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i2bskn%2Fpasswd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i2bskn%2Fpasswd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i2bskn","download_url":"https://codeload.github.com/i2bskn/passwd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244825656,"owners_count":20516592,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","password","rails"],"created_at":"2025-03-21T16:19:31.246Z","updated_at":"2025-03-21T16:19:31.844Z","avatar_url":"https://github.com/i2bskn.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Passwd\n\n[![Gem Version](https://badge.fury.io/rb/passwd.svg)](http://badge.fury.io/rb/passwd)\n\nPasswd is provide hashed password creation and authentication.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"passwd\"\n```\n\nAnd then execute:\n\n```\n$ bundle install\n```\n\nCreate config file(Only Rails) with:\n\n```\n$ bundle exec rails generate passwd:install\n```\n\nThe following file will be created.  \nSee [config](https://github.com/i2bskn/passwd/blob/master/lib/generators/passwd/install/templates/passwd.rb) if not Rails.\n\n- `config/initializers/passwd.rb`\n\n## Usage\n\n### Ruby\n\n```ruby\npasswd = Passwd.current\npasswd.random(10) # Create random password of 10 characters.\npassword = passwd.password_hashing(\"secret\") # Create hashed password from plain text.\npassword == \"secret\" # =\u003e true\nload_password = passwd.load_password(\"hashed_password\") # Load hashed password.\nload_password == \"secret\"\n```\n\n### ActiveRecord with Rails\n\nAdd authentication to your `User` model.  \nModel name is `User` by default, but can be changed in configuration file.\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  with_authenticate\nend\n```\n\n#### Options\n\nUser model The following column are required.  \nColumn name can be changed with the specified options.\n\n- `:id =\u003e :email` Unique value to be used for authentication.\n- `:password =\u003e :password` Column of String to save the hashed password.\n\nUse the `name` column as id.\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  with_authenticate id: :name\nend\n```\n\n#### Authenticate\n\n`authenticate` method is available in both instance and class.  \nReturns user object if the authentication successful.  \nReturns nil if authentication fails or doesn't exists user.  \nInstance method is not required `id`.\n\n```ruby\nuser = User.authenticate(params[:email], params[:password]) # Returns user object or nil.\nuser.authenticate(params[:password]) # Returns true if authentication succeeded.\n```\n\n`set_password` method will be set random password.  \nTo specify password as an argument if you want to specify a password.  \n\n```ruby\ncurrent_user.set_password(\"secret\") # Set random password if not specified a argument.\ncurrent_user.save\n\nnew_user = User.new\nrandom_plain_password = new_user.set_password\nUserMailer.register(new_user, random_plain_password).deliver!\n```\n\n### ActionController\n\nAlready several methods is available in your controller.\n\nIf you want to authenticate the application.  \nUnauthorized access is thrown exception.  \nCan be specified to redirect in configuration file.\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  before_action :require_signin\nend\n```\n\nIf you want to implement the session management.\n\n```ruby\nclass SessionsController \u003c ApplicationController\n  # If you has been enabled `require_signin` in ApplicationController\n  skip_before_action :require_signin\n\n  # GET /signin\n  def new; end\n\n  # POST /signin\n  def create\n    # Returns nil or user\n    @user = User.authenticate(params[:email], params[:password])\n\n    if @user\n      # Save user_id to session\n      signin(@user)\n      redirect_to_referer_or some_path, notice: \"Signin was successful. Hello #{current_user.name}\"\n    else # Authentication fails\n      render action: :new\n    end\n  end\n\n  # DELETE /signout\n  def destroy\n    # Clear session (Only user_id)\n    signout\n    redirect_to some_path\n  end\nend\n```\n\n`current_user` and `signin?` method available in controllers and views.\n\n```ruby\ndef greet\n  name = signin? ? current_user.name : \"Guest\"\n  render text: \"Hello #{name}!!\"\nend\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/i2bskn/passwd.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi2bskn%2Fpasswd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi2bskn%2Fpasswd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi2bskn%2Fpasswd/lists"}