Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
39b5ea6e
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
39b5ea6e
编写于
12月 18, 2010
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Switch from SHA2 to BCrypt (easy Windows compatibility is coming shortly with new compiled gem)
上级
bcf4e4f2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
11 addition
and
9 deletion
+11
-9
activemodel/CHANGELOG
activemodel/CHANGELOG
+1
-1
activemodel/activemodel.gemspec
activemodel/activemodel.gemspec
+2
-0
activemodel/lib/active_model/secure_password.rb
activemodel/lib/active_model/secure_password.rb
+7
-7
activerecord/CHANGELOG
activerecord/CHANGELOG
+1
-1
未找到文件。
activemodel/CHANGELOG
浏览文件 @
39b5ea6e
*Rails 3.1.0 (unreleased)*
* Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with
SHA2
encryption and salting [DHH]
* Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with
BCrypt
encryption and salting [DHH]
*Rails 3.0.2 (unreleased)*
...
...
activemodel/activemodel.gemspec
浏览文件 @
39b5ea6e
...
...
@@ -22,4 +22,6 @@
s
.
add_dependency
(
'activesupport'
,
version
)
s
.
add_dependency
(
'builder'
,
'~> 3.0.0'
)
s
.
add_dependency
(
'i18n'
,
'~> 0.5.0'
)
s
.
add_dependency
(
'bcrypt-ruby'
,
'~> 2.1.2'
)
end
activemodel/lib/active_model/secure_password.rb
浏览文件 @
39b5ea6e
require
'
digest/sha2
'
require
'
bcrypt
'
module
ActiveModel
module
SecurePassword
...
...
@@ -44,13 +44,17 @@ def has_secure_password
module
InstanceMethods
# Returns self if the password is correct, otherwise false.
def
authenticate
(
unencrypted_password
)
password_digest
==
encrypt_password
(
unencrypted_password
)
?
self
:
false
if
BCrypt
::
Password
.
new
(
password_digest
)
==
(
unencrypted_password
+
salt_for_password
)
self
else
false
end
end
# Encrypts the password into the password_digest attribute.
def
password
=
(
unencrypted_password
)
@password
=
unencrypted_password
self
.
password_digest
=
encrypt_password
(
unencrypted
_password
)
self
.
password_digest
=
BCrypt
::
Password
.
create
(
unencrypted_password
+
salt_for
_password
)
end
private
...
...
@@ -58,10 +62,6 @@ def salt_for_password
self
.
password_salt
||=
self
.
object_id
.
to_s
+
rand
.
to_s
end
def
encrypt_password
(
unencrypted_password
)
Digest
::
SHA2
.
hexdigest
(
unencrypted_password
+
salt_for_password
)
end
def
password_must_be_strong
if
@password
.
present?
errors
.
add
(
:password
,
"must be longer than 6 characters"
)
unless
@password
.
size
>
6
...
...
activerecord/CHANGELOG
浏览文件 @
39b5ea6e
*Rails 3.1.0 (unreleased)*
* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with
SHA2
encryption and salting [DHH]. Example:
* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with
BCrypt
encryption and salting [DHH]. Example:
# Schema: User(name:string, password_digest:string, password_salt:string)
class User < ActiveRecord::Base
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录