you store your username and password in the YAML file
---
username: password
Then we load the yaml file using YAML.load_file(file_path)
This will create a hash of { 'username' => 'password' }
Once we have the details, then request user to type in username and password. They are accessible via params[:username] and params[:password]
if hash.key('username') return true && hash['username'] return the matching password then it is a match
then we save the username into the session like so
session[username] = username
If we want to sign out , then we delete the username from the session via session.delete(username)
If certain process you do not want user to do anything, just check if session[:username] is there or not, if not, then user is not log in, then you want to redirect them to homepage.
---
username: password
Then we load the yaml file using YAML.load_file(file_path)
This will create a hash of { 'username' => 'password' }
Once we have the details, then request user to type in username and password. They are accessible via params[:username] and params[:password]
if hash.key('username') return true && hash['username'] return the matching password then it is a match
then we save the username into the session like so
session[username] = username
If we want to sign out , then we delete the username from the session via session.delete(username)
If certain process you do not want user to do anything, just check if session[:username] is there or not, if not, then user is not log in, then you want to redirect them to homepage.
Comments
Post a Comment