Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="/login" method="POST">
- <input type="text" name="name">
- <input type="password" name="password">
- <button type="submit">
- </form>
- def password
- @password ||= BCrypt::Password.new(hashed_password)
- end
- def password=(new_password)
- @password = BCrypt::Password.create(new_password)
- self.hashed_password = @password
- end
- def authenticate(given_password)
- password == given_password
- end
- post '/login' do
- p params[:name]
- @user = User.find_by(name: params[:name])
- p @user
- if @user && @user.authenticate(params[:password])
- session[:id] = @user.id
- redirect '/show_all_users'
- else
- @errors = "Login failed"
- erb :login
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement