Rails typically uses an existing library. Authentication is easy to do wrong, and the problem has been solved so many times that it is rarely worth the effort to solve it again. If you are interested in writing your own implementation, I will describe how modern authentication works.
The naive method of user authentication is to store your password in a database and compare it with the password that the user represents. It is simple but incredibly unsafe. Anyone who can read your database can view any password. Even if you install database access controls, you (and your users) are vulnerable to anyone cheating on them.
- - , , . - - . , , , . , . , , reset, .
, , . , , : , . . , - , , - , . , , , .
, , , ( xor'd) , , . , . , ; ( ), .
: , , , , . - , , (!) , .