Tôi đang tạo biểu mẫu đăng ký cơ bản bằng ruby trên đường ray (tôi tương đối mới đối với đường ray) và những gì tôi muốn biết là làm cách nào để mã hóa mật khẩu của người dùng mới (vì lý do bảo mật rõ ràng)?Tôi làm cách nào để thêm mã hóa cơ bản vào mật khẩu?
Dưới đây là trang web của tôi đăng ký:
<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 %>
Và bộ điều khiển tài khoản:
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
Bất kỳ trợ giúp sẽ được đánh giá cao. Cảm ơn trước.
liên kết này không hoạt động ngay bây giờ. Đây là tài liệu của 'has_secure_password': http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html – Brian
Cảm ơn Brian. Tôi đã cập nhật liên kết. – allesklar