我即将开始在我们公司设立一个仅限员工的Rails应用程序来处理敏感信息.将会有防火墙,物理安全措施等.我现在关心的是应用程序的登录过程.
我想使用Devise进行身份验证.Devise最安全的配置是什么?
我想我会做以下事情:
config.paranoid这样攻击者无法判断他们是否猜到了有效的电子邮件地址一些我不确定的具体事情,用devise.rb斜体字引用:
我还缺少什么?
我有这个加密密码的脚本,但我不知道如何反转它并解密它.这可能是一个非常简单的答案,但我不明白该怎么做.
#!/usr/bin/perl
use Crypt::Eksblowfish::Bcrypt;
use Crypt::Random;
$password = 'bigtest';
$encrypted = encrypt_password($password);
print "$password is encrypted as $encrypted\n";
print "Yes the password is $password\n" if check_password($password, $encrypted);
print "No the password is not smalltest\n" if !check_password('smalltest', $encrypted);
# Encrypt a password
sub encrypt_password {
my $password = shift;
# Generate a salt if one is not passed
my $salt = shift || salt();
# Set the cost to 8 and append a NUL
my $settings = '$2a$08$'.$salt;
# Encrypt it …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的Rails应用程序设置登录功能,当我按下登录按钮时,我收到一条bcrypt错误消息:
LoadError in SessionsController#create
cannot load such file -- bcrypt
Run Code Online (Sandbox Code Playgroud)
是否有其他人收到此错误?我有最新版本的bcrypt,我正在按照教程告诉我的做法.
用户模型:我在所谓的错误行周围放了星号.
class User < ActiveRecord::Base
****has_secure_password****
end
Run Code Online (Sandbox Code Playgroud)
会话控制器:
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by(id: params[session][:id])
if user && user.authenticate(params[:session][:password])
log_in user
redirect_to root_path
else
flash.now[:danger] = 'Invalid'
render 'new'
end
end
def destroy
end
end
Run Code Online (Sandbox Code Playgroud)
ApplicationController中:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include SessionsHelper
end
Run Code Online (Sandbox Code Playgroud)
SessionsHelper:
module SessionsHelper
def log_in(user)
session[:user_id] = user.id
end
end
Run Code Online (Sandbox Code Playgroud)
的Gemfile:
gem 'bcrypt', '~> 3.1.7'
Run Code Online (Sandbox Code Playgroud)
会话/新视图:
<div …Run Code Online (Sandbox Code Playgroud) 对于我正在处理的应用程序,nodejs需要验证PHP创建的哈希值,反之亦然.
问题是,PHP中生成的哈希(通过Laravel的Hash类,只使用PHP的password_hash函数)在node.js中测试时返回false.
以下node.js脚本:
var bcrypt = require('bcrypt');
var password = 'password';
var phpGeneratedHash = '$2y$10$jOTwkwLVn6OeA/843CyIHu67ib4RixMa/N/pTJVhOjTddvrG8ge5.';
var nodeGeneratedHash = '$2a$10$ZiBH5JtTDtXqDajO6f4EbeBIXGwtcGg2MGwr90xTH9ki34SV6rZhO';
console.log(
bcrypt.compareSync(password, phpGeneratedHash) ? 'PHP passed' : 'PHP failed',
bcrypt.compareSync(password, nodeGeneratedHash) ? 'nodejs passed' : 'nodejs failed'
);
Run Code Online (Sandbox Code Playgroud)
输出:'PHP失败的nodejs传递',而以下的PHP脚本:
<?php
$password = 'password';
$phpGeneratedHash = '$2y$10$jOTwkwLVn6OeA/843CyIHu67ib4RixMa/N/pTJVhOjTddvrG8ge5.';
$nodeGeneratedHash = '$2a$10$ZiBH5JtTDtXqDajO6f4EbeBIXGwtcGg2MGwr90xTH9ki34SV6rZhO';
print password_verify($password, $phpGeneratedHash) ? 'PHP passed' : 'PHP failed';
print password_verify($password, $nodeGeneratedHash) ? 'nodejs passed' : 'nodejs failed';
Run Code Online (Sandbox Code Playgroud)
输出'PHP传递的nodejs传递'.
我已经运行使用PHP 5.5.18在Ubuntu 14.04.1测试,Node.js的v0.10.32和故宫bcrypt模块.
我正在使用C#和BCrypt.Net来哈希我的密码.
例如:
string salt = BCrypt.Net.BCrypt.GenerateSalt(6);
var hashedPassword = BCrypt.Net.BCrypt.HashPassword("password", salt);
//This evaluates to True. How? I'm not telling it the salt anywhere, nor
//is it a member of a BCrypt instance because there IS NO BCRYPT INSTANCE.
Console.WriteLine(BCrypt.Net.BCrypt.Verify("password", hashedPassword));
Console.WriteLine(hashedPassword);
Run Code Online (Sandbox Code Playgroud)
如果没有在任何地方保存盐,BCrypt如何用哈希验证密码.我唯一的想法是,它以某种方式在哈希的末尾附加盐.
这是正确的假设吗?
我有点新玩框架和密码哈希.我试图找到一些哈希密码的解决方案,我找到了BCrypt.你认为这对哈希密码是否足够好.如果它很好,我怎样才能让它在Play框架中运行?(我正在使用游戏2.1.3)谢谢!
我正在尝试为我正在制作的节点应用程序配置Bcrypt,并且有几个关于盐的问题,我希望有人可以帮助我们回答.
什么是盐'圆'?例如,在GitHub的文档(https://github.com/kelektiv/node.bcrypt.js/)它使用一个盐一轮的10是什么意思是什么呢?
Bcrypt生成的盐总是一样吗?例如,如果我将用户的散列密码保存到数据库,那么它用于散列密码的盐是否与每个密码相同?
如何储存盐?是否可以抵御潜在的攻击?
我正在尝试npm install使用Windows 7 Ultimate x64 安装bycrpt .这是我的安装日志:
D:\Dropbox\Projekte\RZ\Finance-Man-GUI\node_modules\bcrypt>node "C:\Program File
s\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node
-gyp.js" rebuild
npm http GET https://registry.npmjs.org/mime/1.2.6
npm http 304 https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/mkdirp
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/hooks/0.2.1
npm http 304 https://registry.npmjs.org/mongodb/1.2.8
npm http 304 https://registry.npmjs.org/ms/0.1.0
npm http 304 https://registry.npmjs.org/sliced/0.0.3
npm http 304 https://registry.npmjs.org/muri/0.1.0
npm http 304 https://registry.npmjs.org/mime/1.2.6
npm http GET https://registry.npmjs.org/crc/0.2.0
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http GET https://registry.npmjs.org/bytes/0.1.0
npm http GET https://registry.npmjs.org/formidable/1.0.11
npm http GET https://registry.npmjs.org/qs/0.5.1
npm http GET https://registry.npmjs.org/bson/0.1.5
C:\Program …Run Code Online (Sandbox Code Playgroud) 在阅读了Jeff Atwood关于存储密码的帖子后,我偶然发现了BCrypt.net,这让我想到了Thomas Ptacek建议使用BCrypt来存储密码.这最终促成了我对BCrypt的C#实现
在上面最后一个链接的评论中,有人问"为什么GenerateSalt(30)永远服用,但GenerateSalt(31)似乎根本不花时间?"
我运行了BCrypt.HashPassword(密码,BCrypt.GenerateSalt(31))并在0毫秒内得到了我的结果.
我已经运行BCrypt.HashPassword("密码",BCrypt.GenerateSalt(30))超过5分钟,但仍然没有结果.
我意识到我们可能不需要随机生成的30个字符的盐来创建我们的密码哈希值(或BCrypt案例中的不可逆加密)多年.编辑我应该读一下代码,logRounds与salt长度没有任何关系.谢谢Aaronaught.
那么,为什么GenerateSalt(31)几乎立即返回一个值(当它需要大约两倍于GenerateSalt(30)的时候?
UPDATE
这是修复:
private byte[] CryptRaw(byte[] password, byte[] salt, int logRounds) {
// ... snip ...
uint rounds = 1U << logRounds;
// ... snip
}
Run Code Online (Sandbox Code Playgroud) 我的php代码生成一个哈希,password_hash用于存储在数据库中.以下是PHP代码:
$hash = password_hash($value, PASSWORD_BCRYPT, array('cost' => $cost));
Run Code Online (Sandbox Code Playgroud)
我想在nodejs中针对此哈希验证/检查密码.
我看到了很多节点模块(bcrypt,phpass,node-bcrypt),但是所有节点模块都给我错误.下面是在php中生成的示例哈希,我试图在nodejs中验证.
var hash = '$2y$08$9TTThrthZhTOcoHELRjuN.3mJd2iKYIeNlV/CYJUWWRnDfRRw6fD2';
var bcrypt = require('bcrypt');
bcrypt.compare("secret", hash, function(err, res) {
console.log(res);
});
Run Code Online (Sandbox Code Playgroud)
(这里的秘密是真实的密码)
我目前的解决方法是通过节点调用php脚本来验证(对于需要解决方法的任何人)
var exec = require('child_process').exec;
var cmd = 'php verify.php password encryped_pasword';
exec(cmd, function (error, stdout, stderr) {
// output is in stdout
console.log(stdout);
//If stdout has 1 it satisfies else false
});
Run Code Online (Sandbox Code Playgroud)
这是一个黑客,并不是这个问题的好答案.有没有办法验证nodejs中的密码而不使用这样的解决方法?