我在rails 3上使用devise(当前gem)中的数据库身份验证,并且在尝试使用用户名/密码登录时出现以下错误.
no such file to load -- bcrypt_ext
This error occurred while loading the following files:
bcrypt
bcrypt_ext
Run Code Online (Sandbox Code Playgroud)
我之前已经"成功安装了bcrypt-ruby-2.1.2"宝石.
有任何想法吗?我也试过给Bundler git repo地址并获取master,但它没有解决问题.
C中至少有两个Bcrypt实现:
我应该使用哪一个作为新项目的基础?请注意,我不需要向后兼容性,因此我的选择将完全取决于哪个实现被认为是最新的和维护的.另外,我很好奇哪一个用作大多数非C语言绑定的基础.
我很困难,试图让我的密码成功地与使用节点的bcrypt进行比较.也许我错过了一些东西,但在创建帐户时,我在注册方法中执行以下操作(某些代码缩写):
bcrypt.genSalt(10, function(err, salt) {
if(err) {
}
bcrypt.hash(user.Password, salt, function(err, hash) {
console.log('hashing and saving');
db.query(db insert code, function (error, rows, fields) {
if(error) {
console.log(error);
res.setHeader('500', { 'Content-Type': 'x-application/json'});
res.send({UserId: 0, ErrorMessage: 'Something terrible happened.'});
} else {
console.log('User created : ' + rows.insertId);
res.setHeader('200', { 'Content-Type': 'x-application/json'});
res.send({UserId: rows.insertId});
}
});
});
});
return next();
Run Code Online (Sandbox Code Playgroud)
一切正常.我的数据库有加密密码.但是当用户登录时,我无法从bcrypt.compare获得成功结果:
db.query(get account code, function(error, rows, fields) {
if(rows.length == 1) {
bcrypt.compare(request.params.password, rows[0].Password, function(err,res) {
if(err) { console.log(err.toString()); }
if(res == …Run Code Online (Sandbox Code Playgroud) 我想创建一个函数或类似Cron的东西,它执行链接(在Laravel中),类似于密码.我有两个解决方案.但哪一个更好用:
选项1(哈希):
<?php
// Page 1
$salt = "my-random-hash";
$key = hash('sha256', date('Y-m-d').$salt);
// <-- Insert go to page and send GET with $key code here
// Page 2
$salt = "my-random-hash";
$key = hash('sha256', date('Y-m-d').$salt);
if ($key == $pageOneKey) {
// Execute some code
}
Run Code Online (Sandbox Code Playgroud)
选项2(bcrypt):
<?php
// Page 1
$key = Crypt::encrypt(date('Y-m-d'));
// <-- Insert go to page and send GET with $key code here
// Page 2
$key = date('Y-m-d');
$pageOneKey = Crypt::decrypt($key);
if ($key == $pageOneKey) …Run Code Online (Sandbox Code Playgroud) 我遇到了BCrypt密码的问题:我的User模型都设置为has_secure_password和validates_presence_of :password.
重点是BCrypt使用password,password_confirmation但在模式中只有password_digest字段.
夹具抱怨该password字段不存在.
我怎么能避免这个?
谢谢
我加密用户的密码并保存到db.然后到用户登录,比较哈希密码和普通密码,我收到crypto/bcrypt: hashedPassword is not the hash of the given password错误.怎么了 ?
func encryptPassword(password string) (string, error) {
bytePass := []byte(password)
hashedPassword, err := bcrypt.GenerateFromPassword(bytePass, bcrypt.DefaultCost)
if err != nil {
log.Printf("ERROR:EncryptPassword: %s", err.Error())
}
return string(hashedPassword), err
}
func (i *Impl) Register(user User) bool {
hashedPass, err := encryptPassword(user.Password)
if err != nil {
return false
}
user.Password = hashedPass
if err := i.DB.Create(&user).Error; err != nil {
log.Printf("ERROR:Register: %s", err.Error())
return false
}
return true
}
func …Run Code Online (Sandbox Code Playgroud) 我克隆了一个使用'bcrypt'模块的sails项目,当我尝试使用命令安装它时 -
npm install --save bcrypt
Run Code Online (Sandbox Code Playgroud)
但它给了我以下错误!!!.我也使用npm版本@ 3.6.0和节点版本@ 5.6.0.Am无法解决此错误如下所示:
> bcrypt@0.8.5 install C:\Users\vikas\Documents\batua-web\node_modules\bcrypt
> node-gyp rebuild
> C:\Users\vikas\Documents\batua-web\node_modules\bcrypt>if not defined npm_config_node_gyp (node "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild )Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
> C:\Users\vikas\Documents\batua-web\node_modules\bcrypt\build\bcrypt_lib.vcxproj(20,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
> gyp …Run Code Online (Sandbox Code Playgroud) 我已经将node.js v6.9.1和npm版本4.1.2一起安装了,我已经将这个组合用于了一些项目
现在我想bcrypt在我的项目中使用npm包,但安装失败了
npm install bcrypt --save
Run Code Online (Sandbox Code Playgroud)
我也尝试使用admin priviledges运行此命令,但无济于事
这是我得到的错误
> bcrypt@1.0.2 install C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcry
pt
> node-pre-gyp install --fallback-to-build
node-pre-gyp ERR! Tried to download(404): https://github.com/kelektiv/node.bcryp
t.js/releases/download/v1.0.2/bcrypt_lib-v1.0.2-node-v48-win32-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for bcrypt@1.0.2 and node@6.9.1 (
node-v48 ABI) (falling back to source compile with node-gyp)
C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt>if not defined npm_c
onfig_node_gyp (node "C:\Users\ttheiner\AppData\Roaming\npm\node_modules\npm\bin
\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" clean ) else (node
"" clean )
C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt>if not defined npm_c
onfig_node_gyp (node "C:\Users\ttheiner\AppData\Roaming\npm\node_modules\npm\bin
\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" configure --fallback
-to-build --module=C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt\l
ib\binding\bcrypt_lib.node --module_name=bcrypt_lib --module_path=C:\Users\tthei
ner\NodeProjects\authtest\node_modules\bcrypt\lib\binding ) …Run Code Online (Sandbox Code Playgroud) 在MySQL中搜索存储BCrypt哈希的正确方法我发现了这个问题,这只会让我更加困惑.
接受的答案指出我们应该使用:
CHAR(60) BINARY or BINARY(60)
但是评论中的其他人认为我们应该使用:
CHAR(60) CHARACTER SET latin1 COLLATE latin1_bin
甚至:
COLLATE latin1_general_cs
我不是数据库的专家,所以任何人都可以解释我所有这些选项之间的区别,哪一个真的更适合存储BCrypt哈希?
继这个问题之后.
我觉得我几乎就在那里,但我对异步的不完全理解阻止了我解决这个问题.我基本上试图使用bcrypt来散列密码并决定分离hashPassword函数,以便我可以在应用程序的其他部分使用它.
hashedPassword 保持返回undefined虽然...
userSchema.pre('save', async function (next) {
let user = this
const password = user.password;
const hashedPassword = await hashPassword(user);
user.password = hashedPassword
next()
})
async function hashPassword (user) {
const password = user.password
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(password, saltRounds, function(err, hash) {
if (err) {
return err;
}
return hash
});
return hashedPassword
}
Run Code Online (Sandbox Code Playgroud)