Guest User

Untitled

a guest
Feb 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. Login Form
  2. ==========
  3.  
  4. <h1>Login</h1>
  5. <%= error_messages_for 'individual' %>
  6. <%= start_form_tag :action=> "login" %>
  7. <h3>Login</h3>
  8.  
  9. <label for="individual_username">Login:</label><br/>
  10. <%= text_field "individual", "username", :size => 20 %><br/>
  11.  
  12. <label for="user_password">Password:</label><br/>
  13. <%= password_field "individual", "password", :size => 20 %><br/>
  14.  
  15. <%= submit_tag "Submit" %>
  16.  
  17. <%= link_to 'Register', :action => 'signup' %> |
  18. <%= link_to 'Forgot my password', :action => 'forgot_password' %>
  19.  
  20. <%= end_form_tag %>
  21.  
  22.  
  23.  
  24.  
  25. Individuals_Controller
  26. ======================
  27.  
  28. def login
  29. if request.post?
  30. if session[:individual] = Individual.authenticate(params[:individual][:username], params[:individual][:password])
  31. flash[:message] = "Login successful"
  32. redirect_to_stored
  33. else
  34. flash[:warning] = "Login unsuccessful"
  35. end
  36. end
  37. end
  38.  
  39.  
  40. Individuals Model
  41. =================
  42.  
  43. def self.encrypt(string, salt)
  44. return Digest::SHA1.hexdigest(string+salt)
  45. end
  46.  
  47. def self.authenticate(username, pass)
  48. resultset=find(:first, :conditions=>["username = ?", username])
  49. return nil if resultset.nil?
  50. return resultset if Individual.encrypt(pass, resultset.created_on.to_s[0,19])==resultset.password
  51. nil
  52. end
Add Comment
Please, Sign In to add comment