I’m creating a basic sign up form using ruby on rails (I’m relatively new to rails), and what I want to know is how can I encrypt the new user’s password (for obvious security reasons)?
Here’s my registration page:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
$.noConflict();
jQuery(document).ready(function($) {
$('a.close').click(function(){
$(this).parent().fadeOut();
});
});
</script>
<% if !flash.now[:notice].blank? %>
<div class="alert-message error">
<a class="close" href="#">×</a>
<p><strong><%= flash.now[:notice][0] %></strong></p>
</div>
<% end %>
<div class="alert-message info">
<p><strong>Join us. It's as simple as 1 2 3.</strong></p>
</div>
<% form_for :user do |f| %>
<p> Email: <br /> <%= f.text_field :email %></p>
<p> Name: <br /> <%= f.text_field :name %></p>
<p> Username:<br /><%= f.text_field :username %></p>
<p> Password: <br /> <%= f.password_field :password %></p>
<p> Blog <i>(optional)</i>: <br /> <%= f.text_field :blog %></p>
<p><%= submit_tag "Create User", :disable_with => "Please wait...", :class => "btn primary" %></p>
<% end %>
And the User controller:
class UsersController < ApplicationController
def register
@user = User.new(params[:user])
if(request.post? and @user.save)
flash[:notice] = "Account Created Successfully"
redirect_to root_path
else
flash.now[:notice] = @user.errors.full_messages
end
end
def destroy
@user = User.find(params[:id])
@user.destroy
redirect_to root_path
end
end
Any help would be appreciated.
Thanks in advance.
Here you go:
And the for the authentication:
But like allesklar wrote, Rails 3.1 will be a good choice. Watch the Railscasts on the subject.