Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Login Form
- ==========
- <h1>Login</h1>
- <%= error_messages_for 'individual' %>
- <%= start_form_tag :action=> "login" %>
- <h3>Login</h3>
- <label for="individual_username">Login:</label><br/>
- <%= text_field "individual", "username", :size => 20 %><br/>
- <label for="user_password">Password:</label><br/>
- <%= password_field "individual", "password", :size => 20 %><br/>
- <%= submit_tag "Submit" %>
- <%= link_to 'Register', :action => 'signup' %> |
- <%= link_to 'Forgot my password', :action => 'forgot_password' %>
- <%= end_form_tag %>
- Individuals_Controller
- ======================
- def login
- if request.post?
- if session[:individual] = Individual.authenticate(params[:individual][:username], params[:individual][:password])
- flash[:message] = "Login successful"
- redirect_to_stored
- else
- flash[:warning] = "Login unsuccessful"
- end
- end
- end
- Individuals Model
- =================
- def self.encrypt(string, salt)
- return Digest::SHA1.hexdigest(string+salt)
- end
- def self.authenticate(username, pass)
- resultset=find(:first, :conditions=>["username = ?", username])
- return nil if resultset.nil?
- return resultset if Individual.encrypt(pass, resultset.created_on.to_s[0,19])==resultset.password
- nil
- end
Add Comment
Please, Sign In to add comment