背景:
我想添加一个登录到我的小网站,这是一个在线php应用程序,我想建立,以便将来能够承担很多用户活动.
在我进一步研究实现LightOpenID之前,我想添加一个正常的登录.我正在学习的这本书名为Head First PHP&MySQL(2008),本章的最终代码SHA('$user_password')用作mysql查询的一部分.
当我对Jeff Atwood的写作感兴趣时,我很清楚bcrypt的scrypt.但是看到没有scrypt的php实现并且没有专用服务器来运行它,我决定至少考虑实现bcrypt.
但是我并不完全天真,我知道我应该注意不要过度扩展我非常谦逊的托管资源.php应用程序本身应始终先出现在资源之前.
Andrew Moore的方法看起来不错(虽然我必须看看如何在我的主机使用的php 5.2.17上实现它)并且它附带了硬件速度提示:
您应该选择导致200-250毫秒工作的轮数.bcrypt安全的部分原因是它很慢.你必须确保有一些保持这种特性的回合. - 安德鲁摩尔
另一个用户表示,对于他来说,跑步microtime()给予Bcrypt(9)0.314,因此接近最佳状态.
问题:
看来我只有非常谦逊的资源可供我使用,我想充分利用它们,留下最多的PHP应用程序本身,我还是更好地使用Bcrypt(4)而不是其他东西?
Bcrypt(4)几乎立即返回true,但是它仍然保留了Moore所说的那个特性吗?(这会是关于RAM的部分会让GPU更难实现吗?)或者SHA512 或其他什么实际上会更快但更安全在此刻?
我希望Bcrypt(4)在这种情况下获胜,但我知道对吗?:p
我之前从未编写过用户身份验证系统,对于这个项目我需要平衡安全性和效率(这意味着我不能花费数百个工时来处理安全性,但我需要保留密码和登录信息安全).
我正在使用带有快速框架和通行证的Node.js进行身份验证和会话.
到目前为止,我所做的研究显示了需要解决的三个问题.在今天之前,我几乎不知道如果这些问题存在任何常见的解决方案,并且几个小时的随机啄掉研究并不能让我对我找到的答案的完整性有信心.
问题:
不要将未加密的纯文本密码存储在数据库中(可能的答案:盐/哈希密码在服务器上并将哈希值存储在数据库中.)
不要通过非安全的http连接传递纯文本密码(可能的答案:A - 仅使用Https进行身份验证过程.之后使用http.B - 在登录页面向用户发送随机盐,哈希密码客户端,然后取消哈希并重新加密数据库存储.)
不要使用GPU加密方法,GPU每秒可以破解700,000,000个密码.(可能的答案:bcrypt)
这些只是我在3小时研究中发现的最明智的答案.我不知道这些是否足够,它们的弱点是什么,或者可能有哪些替代品.我还要感谢任何进一步的见解(另请注意:我甚至不确定 - https是否会在传输时充分保护密码?)
我正在使用bcrypt生成salt和hash密码,但我不认为它是非常安全的.当我使用以下代码时:
bcrypt.genSalt(10, function(err, salt) {
user.salt = salt;
bcrypt.hash(password, salt, function(err, hash) {
user.hashed_password = hash;
console.log(user.salt);
console.log(user.hashed_password);
user.save(function(err) {
if (err) console.log(err);
console.log("saved");
});
});
});
Run Code Online (Sandbox Code Playgroud)
在一个示例中,salt是:$2a$10$mFFjRpY1Vrq7Fy1fFp0fMO并且hashed_password是:$2a$10$mFFjRpY1Vrq7Fy1fFp0fMOVnlv9cKgAFdCQ5xdtlP6UoKz90i1FMu
散列密码的开头与salt完全相同.如果攻击者可以访问salt,他是否只能从hashed_password中删除盐并强制使用或使用预定哈希值的表来确定密码?
我一直以为这应该是哈希密码的顺序:
hash(salt + password)
Run Code Online (Sandbox Code Playgroud)
不:
salt + hash(password)
Run Code Online (Sandbox Code Playgroud) 如果我不是描述性的话,这里的第一个问题请原谅我.运行Ruby 1.8.7 w/rails 2.3.5如果我运行任何rails或rake任务我得到
/home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/rubygems-bundler-1.4.2/lib/rubygems-bundler/noexec.rb:75:in `setup': undefined method `name' for #<Array:0x7f45a2fe73a8> (NoMethodError)
from /home/mathew/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `map'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/rubygems-bundler-1.4.2/lib/rubygems-bundler/noexec.rb:75:in `each'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/rubygems-bundler-1.4.2/lib/rubygems-bundler/noexec.rb:75:in `map'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/rubygems-bundler-1.4.2/lib/rubygems-bundler/noexec.rb:75:in `setup'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/rubygems-bundler-1.4.2/lib/rubygems-bundler/noexec.rb:114:in `check'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/rubygems-bundler-1.4.2/lib/rubygems-bundler/noexec.rb:121
from /home/mathew/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /home/mathew/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/rubygems-bundler-1.4.2/lib/rubygems_executable_plugin.rb:4
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/executable-hooks-1.2.6/lib/executable-hooks/hooks.rb:50:in `call'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/executable-hooks-1.2.6/lib/executable-hooks/hooks.rb:50:in `run'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/executable-hooks-1.2.6/lib/executable-hooks/hooks.rb:49:in `each'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@global/gems/executable-hooks-1.2.6/lib/executable-hooks/hooks.rb:49:in `run'
from /home/mathew/.rvm/gems/ruby-1.8.7-p374@wholesale/bin/ruby_executable_hooks:10
Run Code Online (Sandbox Code Playgroud)
我的宝石清单是:
*** LOCAL GEMS ***
actionmailer (2.3.5)
actionpack (2.3.5)
activerecord (2.3.5)
activeresource (2.3.5)
activesupport (2.3.5)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
bundler (1.3.5)
bundler-unload (1.0.2)
daemons (1.0.10)
delayed_job (2.0.4)
executable-hooks (1.2.6) …Run Code Online (Sandbox Code Playgroud) 这是来自github页面:
require 'bcrypt'
class User < ActiveRecord::Base
# users.password_hash in the database is a :string
include BCrypt
def password
@password ||= Password.new(password_hash)
end
def password=(new_password)
@password = Password.create(new_password)
self.password_hash = @password
end
end
Run Code Online (Sandbox Code Playgroud)
看来要访问密码方法,您需要从create方法中将其作为属性调用:
@user.password = user_params[:password]
@user.save
Run Code Online (Sandbox Code Playgroud)
好的?但现在储存的盐在哪里?我根本就没有得到它,这又如何远程安全?
要检索散列密码,您需要以下方法:
def password
@password ||= Password.new(password_hash)
end
Run Code Online (Sandbox Code Playgroud)
并将其称为属性:
if @user.password == params[:password]
give_token
else
false
end
Run Code Online (Sandbox Code Playgroud)
所以看来一切都在没有盐的情况下......它是如何做到的?
这意味着我现在只需要在我的数据库中使用一列来处理密码,对吧?password或者password_hash代替password_salt | password_hash?
那么为什么github页面会这样说:
但即使这有弱点 - 攻击者可以通过相同的算法运行可能的密码列表,将结果存储在一个大数据库中,然后通过哈希查找密码:
Run Code Online (Sandbox Code Playgroud)PrecomputedPassword.find_by_hash(<unique gibberish>).password #=> "secret1" Salts
然后这就是我真正得到的:
Run Code Online (Sandbox Code Playgroud)The solution to …
编辑:在Github回购中打开问题. https://github.com/arunoda/meteor-up/issues/87
我试图设置Meteor来运行流星应用程序.
这是我跑步时得到的错误 mup deploy
调用部署过程:FAILED
-----------------------------------STDERR-----------------------------------
e-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /opt/give/tmp/bundle/programs/server/node_modules/bcrypt
gyp ERR! node -v v0.10.28
gyp ERR! node-gyp -v v0.13.0
gyp ERR! not ok
npm ERR! bcrypt@0.7.8 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@0.7.8 install script.
npm ERR! This is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! …Run Code Online (Sandbox Code Playgroud) 我一直使用MD5加密密码,但我读到它应该不再使用,而是使用bcrypt ..
我正在使用zendframework 2,在那里我发现它描述了bcrypt配置如下:
$bcrypt = new Bcrypt(array(
'salt' => 'random value',
'cost' => 11
));
Run Code Online (Sandbox Code Playgroud)
什么是盐,成本是多少?它们如何被使用?
我一直在探索Twin-Bcrypt JavaScript库,并发现了一件奇怪的事情.有一次,我在服务器端使用PHP创建了自己的salt base64_encode(openssl_random_pseudo_bytes(16))并在TwinBcrypt.hash()函数中使用它,由于库中的常规模式不匹配,因此响应盐无效.所以,模式是:
var SALT_PATTERN = /^\$2[ay]\$(0[4-9]|[12][0-9]|3[01])\$[.\/A-Za-z0-9]{21}[.Oeu]/;
Run Code Online (Sandbox Code Playgroud)
我的盐看起来很好,除了一件事 - 这到底是什么 - [.Oeu]?
我的第一个问题是,为什么他们希望盐以点,或O,或e结束,或者你?据我所知openssl_random_pseudo_bytes()生成安全的CSPRNG,但由于模式JS库不想接受它.
第二个问题 - 盐是否有任何安全理由以/[.Oeu]/模式结束?
我会非常感谢任何帮助,因为没有太多关于它的信息.
我想在将数据存储到数据库之前使用node.js bcrypt来哈希密码.
此链接提供文档. https://github.com/kelektiv/node.bcrypt.js
以下是散列密码的示例.
var bcrypt = require('bcrypt');
const saltRounds = 10;
const myPlaintextPassword = 's0/\/\P4$$w0rD';
var salt = bcrypt.genSaltSync(saltRounds);
var hash = bcrypt.hashSync(myPlaintextPassword, salt);
// Store hash in your password DB.
Run Code Online (Sandbox Code Playgroud)
这是检查密码的代码.
// Load hash from your password DB.
bcrypt.compareSync(myPlaintextPassword, hash); // true
Run Code Online (Sandbox Code Playgroud)
这是我不明白的.在bcrypt.compareSync,为什么没有参数salt?由于散列是从salt生成的,为什么比较明文密码不涉及散列中使用的原始盐?