Active Record Authentication

Tarooj Khan
2 min readDec 7, 2020

Authentication in general terms means to check if something is valid or verify something. It could also mean if something is original or not. It could be used in different ways. But the main purpose is to check something. In Active Record authentication is mainly used for purposes of verifying a user signing into an application and also a user that is already signed in or existing in the database. Active Record helps a programmer authenticate a user with pre-written methods called macros. Macros are methods that write methods for us. So instead of writing a method to authenticate or any other function, programmers can use macros that will help them with that.

Active Record gives macros called BCrypt, authenticate and has_secure password. They are helpful methods and can be used in other methods as well. You define these macros in your application controller and the models will inherit from the application controller. Passwords are something that are susceptible to being stolen. So a programmer must use methods to protect it and also to protect the application from users who are trying to access unauthorized information.

Protecting a password is very and highly important as they can be stolen and information can be accessed. This is where Bcrypt comes into handy. This is a gem that needs to be installed with other gems in an application and gives a handy method called “has_secure_password.” This method takes a password and salts it or you can say hides it. So a password say, “Mike2020” would become something like #@### or some set of…

--

--