We will start with creating a model for the user. We need to create a field called password_digest for storing the encrypted password.
We need to add ‘bcrypt’ gem to the Gemfile as it is used by rails to encrypt the password internally.
ActiveModel::SecurePassword is a module required for generating and validating passwords in rails. In order to enable this module on a particular model, we need to include it. Then access these methods using has_secure_password.
We have already added the ability to create users, password and password confirmation to our system. Let’s quickly check what we have done.
In order to handle the creation of users, we will create a controller.
We also need to setup the routes for users and create a root page. We will modify the users route to make it restful.
Let’s modify the controller and create a new and create method. Make sure you whitelist a limited set of params not permit all.
In order to create signup for the user, we need to add a form for it.
We will create session and session objects in the next part.
Update: You can read the Part 2 of the tutorial here.