Coder Social home page Coder Social logo

passwordcontrol's Introduction

HashControl

Gem Version Coverage Status Build Status

A high level ruby library for control hash algorithms. Designed to make possible to everybody secure the passwords of your clients with any knowledge about security.

Algorithms supported

This library support and abstract the following hash algorithm:

Installation

Add this line to your application's Gemfile:

gem 'password_control'

And then execute:

$ bundle

Or install it yourself as:

$ gem install password_control

Usage

Hashing a password:

This library was structured for simplicity. To Hash a password with a strong algorithm (bcrypt), you just need to:

passControl = PasswordController.new :secret => "The user password"

Setting the desired hash algorithm for the library:

This library supports some algorithms (see algorithms supported section). You can specify the algorithm for use at the time of instantiation:

 # algorithms: sha256, sha384, sha512, scrypt, bcrypt
passControl = PasswordController.new :secret => "User password", :algorithm => "Your option"

For example, let's set scrypt as our algorithm:

passControl = PasswordController.new :secret => "User password", :algorithm => "scrypt"

Now the library will use the scrypt algorithm to hash this secret.

Saving data:

The library need some informations of the hash process to comparisons in the future. To store this informations in database, you will need to call prepareForSave() method:

passControl.prepareForSave()

This method will return all the informations needed for library in a HashMap style. For example:

{:secret => "$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy", :algorithm => "bcrypt"}

Some other algorithms may return the generate salt together.

Restoring from database:

For compare in the future, get the HashMap stored in database and pass as argument to PassControl:

passControl = PasswordController.new HASHMAP_IN_DATABASE

passControl = PasswordController.new {:secret => "$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy", :algorithm => "bcrypt"}

Comparison:

And for compare the hash with the user password, simple use funcion ==

passControl == "user password"

As simple as it sounds!

Salt:

The password_control gem will take care of strong salt generation for each hashing process.

Contributing

  1. Fork it (https://github.com/giovanifss/PasswordControl/fork)
  2. Create your feature branch ('git checkout -b my-feature')
  3. Commit your changes ('git commit -am "add my feature"')
  4. Push to the branch ('git push origin my-feature')
  5. Create a Pull Request

Bug reports and pull requests are welcome on GitHub at https://github.com/giovanifss/PasswordControl.

License

This library is under LGPL license, it means: You may copy, distribute and modify the software provided that modifications are described and licensed for free under LGPL. Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under LGPL, but applications that use the library don't have to be.

For more details see LICENSE.

passwordcontrol's People

Contributors

giovanifss avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.