我正在使用Andrew Moore先生的方法(如何使用bcrypt在PHP中使用哈希密码?)哈希用户的密码.我做的是我有一个注册页面,它使用
$bcrypt = new Bcrypt(12);
$pass = $_POST['password']; //register password field
$hash= $bcrypt->hash($pass);
// then inserts $hash into database with users registered email (I've checked my mysql database and it indeed has an hashed item
Run Code Online (Sandbox Code Playgroud)
然后我有一个登录页面,包括电子邮件和密码字段.我的想法是电子邮件地址在我的数据库中是唯一的.因此,考虑到这一点,我创建了一个脚本,首先检查用户的电子邮件地址,然后如果有现有的,请用此验证哈希密码
$bcrypt = new Bcrypt(12);
$email = $_POST['email']; //from login email field
$pass_l = $_POST['password']; // from login password field
$hash_1= $bcrypt->hash($pass_1);
$chk_email= $dbh->prepare("SELECT password FROM table WHERE email = ?");
$chk_email -> execute(array($email));
while($row = $chk_email->fetch(PDO::FETCH_ASSOC)){
$chk_pass = $row['password']; //inside a …Run Code Online (Sandbox Code Playgroud) 所以我使用的是新的PHP 5.5 Password Hashing API,我不确定我是否正确使用了它.
我已经尝试自动重新登录每次登录,有时我失败了,即使哈希结果是相同的,我觉得我做错了.
它可能是我可能错误的查询函数,因为当我检查phpMyAdmin时哈希甚至没有改变.
if (password_needs_rehash($result_row->user_password_hash, PASSWORD_DEFAULT))
{
$newhash = password_hash(
$_POST['user_password'], PASSWORD_BCRYPT,
['cost' => 12, 'salt' => 'superfreakingsonicdude',]
);
// update hash in database
$this->connection->query(
"UPDATE users SET user_password_hash='" . $newhash .
"' WHERE user_name='".$result_row->user_name."'"
);
}
Run Code Online (Sandbox Code Playgroud)
我实际上是使用bcrypt模块来散列和比较散列密码.
我想要做的是删除bcrypt模块并使用默认crypto库进行散列和比较密码.
这可能吗?
这比使用安全node-bcrypt吗?
你有关于怎么做的任何示例/教程/ doc/link?
或者我实际上是这样做的:
bcrypt.hash(string,secret_key)
bcrypt.compare(string,string,secret_key);
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我只想用加密复制它:
crypto.hash(string,secret_key)
crypto.compare(string,string,secret_key);
Run Code Online (Sandbox Code Playgroud) 我正在编写一个单元测试,说明应该使用 bcrypt 对用户密码进行散列。要断言这一点,我需要能够检查字符串是否看起来像 bcrypt 哈希。
我找不到一个函数来告诉我在字符串上使用了什么散列算法,除了正则表达式之类的方法之外,还有其他方法可以做到吗?
您好我从正在运行的Node.js服务器下载了我的项目副本并尝试运行它但遇到以下错误:
错误:
E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt\node_modules\bindings\bindings.js:79
throw e
^
Error: %1 is not a valid Win32 application.
E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt\build\Release\bcrypt_lib.node
at Error (native)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at bindings (E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt\node_modules\bindings\bindings.js:74:15)
at Object.<anonymous> (E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt\bcrypt.js:3:35)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (E:\Projects\Smart Automation Web\Zigma_copy\automator\api\services\UserManager.js:2:14)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
Run Code Online (Sandbox Code Playgroud)
我是如何尝试运行我的应用程序的:
简短:我无法使用 my.domain.ch 名称从外部(运行 MAC 的本地计算机)登录我的 docker-registry(托管在服务器中心的 ubuntu-vm (14.04LTS) 上)。
我可以使用“docker login http://localhost:5000 ”从运行注册表的ubuntu-machine(vm-2)成功登录
这是我的设置:
vm-1:Ubuntu 14.04 上的 nginx/1.10.1 充当反向代理(此处未安装 docker):
upstream registry {
server vm-2:5000 fail_timeout=5s;
}
server {
listen 80;
server_name my.domain.ch; # server_name ;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name my.domain.ch; # server_name ;
charset utf-8;
keepalive_timeout 5;
add_header Docker-Distribution-Api-Version registry/2.0 always;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
ssl_ecdh_curve secp521r1;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCMSHA384:ECDHE-ECDSA-AES256-SHA384:EC$
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header …Run Code Online (Sandbox Code Playgroud) 我正在学习 Nodejs 背景下的传递哈希,我想知道你会推荐什么盐级别。默认级别是 10,我想知道这对于少于 10 个用户的基本应用程序来说是否足够好。
我知道这个问题已经被问过几次了(比如这里,这里或那里,甚至在Github上,但没有一个答案真正对我有用......
我正在尝试使用 Mongoose 和 Passport 为 NodeJS 应用程序开发身份验证,并使用 Bcrypt-NodeJS 来哈希用户的密码。
在我决定重构用户架构并使用 bcrypt 的异步方法之前,一切都正常运行。创建新用户时哈希仍然有效,但我现在无法根据存储在 MongoDB 中的哈希来验证密码。
bcrypt.compare()总是返回false无论密码正确与否,无论密码是什么(我尝试了几个字符串)。为了保持清晰,一些字段已被删除,但我保留了相关部分。
var userSchema = mongoose.Schema({
// Local authentication
password: {
hash: {
type: String,
select: false
},
modified: {
type: Date,
default: Date.now
}
},
// User data
profile: {
email: {
type: String,
required: true,
unique: true
}
},
// Dates
lastSignedIn: { …Run Code Online (Sandbox Code Playgroud) 我在NodeJS中使用bcrypt来生成密码哈希.Bcrypt docs说我们可以使用genSalt(),compare()和hash()函数的异步版本.
NodeJS是单线程的,因此理论上如果我使用CPU绑定代码,即使使用异步等待也会阻塞线程.如果我在这种情况下使用async await函数,我的应用程序会发生什么变化?CPU绑定代码在什么情况下会受益于使用异步等待模式?
I was trying to implement a functionality where a user can reset a password. I have tried the below code and while I am not getting any error, its not updating the password. The password is the same ie the old password.
my User model file is as follows:-
const mongoose = require('mongoose');
var passportLocalMongoose = require("passport-local-mongoose");
const LoginUserSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
email: {
type: String,
unique: true,
required: true
},
password: { …Run Code Online (Sandbox Code Playgroud) bcrypt ×10
node.js ×6
hash ×3
php ×3
javascript ×2
mongoose ×2
mysql ×2
passwords ×2
async-await ×1
cryptography ×1
nginx ×1
passport.js ×1
phpunit ×1
ubuntu-14.04 ×1