This blog I will tell how to encryption you're form login using Bcrypt. This blog will user the language ruby with the frame work rails, and the appropriate gems.
- The first step is make user your routes for signing are working. Here is an example of code found in my config folder in the routes.rb file.
- Then make sure the gem file the gem bcryp is present, followed by making sure you middle ware, the piece interacting with the cookies and session is present. My middle ware is located in config folder in the application folder.
BONUS: in the dev tools go to application section and select the server, and when interaction with cookies it will render in the format of key and values.
The preparation are complete
- Next we will use Bcrypt's built in features """""has_secure_password """ which utilities other built in features such as password_digest and BCrypt::Engine (salt). For you to to obtain the benefit of all the features the gem provides with regards to security, you will need to go model were the client will create and have there account displayed and place the following information. For this example I used the user model located inside the app folder in the model folder.
Below I will expand about password_digest and salt you will
not need this information for the code work the above is
more then enough
- Create a function which uses take a parameter. In it a salt will be used, it will be best to put to a variable. Then in the function password_digest is used to the command hash_secret, which will take the parameter and the salt variable. This will create a 60 character encryption, greater then the salt being used only and generate a 29 character encryption
- finally another function created to check the password inputted unless it is a match. in this function all the steps will be repeated with the exception of the use of returning two possibility one for granting access and other for rejection.
Top comments (0)