【发布时间】:2014-02-04 05:48:47
【问题描述】:
我对 DataMapper 和 Sinatra 非常陌生,尤其是 attr_encrypted。我想要的是加密存储我的密码,然后能够通过用户名和密码搜索用户。我读了 attr_encrypted 的documentation,但我仍然不知道该怎么办:(
您能否给我一些使用这两种技术的项目示例或告诉我如何更改我的代码以使其工作:(
我的用户类:
class User
include DataMapper::Resource
attr_encryptor :password, :key => 'secret key'
property :id, Serial
property :encrypted_password, Text
end
当我保存用户时,我会这样做:
username = params[:username]
password = params[:password]
user = User.new(:username => username, :encrypted_password => password)
user.save
这是保存原始密码,而不是加密的。
而且我不知道如何在密码被加密时搜索用户:(
现在是这样的:
@user = User.all(:username => username, :password => password)
请原谅我的新手问题,但我真的不太明白:(
提前非常感谢您!
【问题讨论】:
标签: ruby sinatra ruby-datamapper attr-encrypted