标签: bcrypt

如何将 bcryptjs 与 ES6 NodeJS 一起使用

我正在尝试bcryptjs在我的 React 项目中使用 package。我收到以下错误:

\n
Could not find a declaration file for module 'bcryptjs'. \xe2\x80\x98\xe2\x80\xa6/node_modules/bcryptjs/index.js' \nimplicitly has an 'any' type.\nTry `npm i --save-dev @types/bcryptjs` if it exists or add a new declaration (.d.ts)\nfile containing `declare module 'bcryptjs';`\n
Run Code Online (Sandbox Code Playgroud)\n

运行npm i --save-dev @types/bcryptjs使导入错误消失,但是当我尝试使用包中的变量时,找不到它们。

\n

NodeJS版本是node v16.17.0,也使用TS。

\n

我该如何修复它?谢谢

\n

javascript bcrypt node.js typescript reactjs

5
推荐指数
1
解决办法
2260
查看次数

BCrypt说长,类似的密码是等价的 - 我,宝石或密码学领域的问题?

我一直在试验BCrypt,并发现了以下内容.如果重要的话,我正在运行ruby 1.9.2dev(2010-04-30 trunk 27557)[i686-linux]

require 'bcrypt' # bcrypt-ruby gem, version 2.1.2

@long_string_1 = 'f287ed6548e91475d06688b481ae8612fa060b2d402fdde8f79b7d0181d6a27d8feede46b833ecd9633b10824259ebac13b077efb7c24563fce0000670834215'
@long_string_2 = 'f6ebeea9b99bcae4340670360674482773a12fd5ef5e94c7db0a42800813d2587063b70660294736fded10217d80ce7d3b27c568a1237e2ca1fecbf40be5eab8'

def salted(string)
  @long_string_1 + string + @long_string_2
end

encrypted_password = BCrypt::Password.create(salted('password'), :cost => 10)
puts encrypted_password #=> $2a$10$kNMF/ku6VEAfLFEZKJ.ZC.zcMYUzvOQ6Dzi6ZX1UIVPUh5zr53yEu

password = BCrypt::Password.new(encrypted_password)

puts password.is_password?(salted('password')) #=> true
puts password.is_password?(salted('passward')) #=> true
puts password.is_password?(salted('75747373')) #=> true
puts password.is_password?(salted('passwor')) #=> false
Run Code Online (Sandbox Code Playgroud)

起初我认为一旦密码达到一定长度,所有散列中的差异就会丢失,只有当它们非常不相似(即不同的长度)时才会被识别为不同.从我所知的散列函数来看,这对我来说似乎不太合理,但我没有看到更好的解释.

然后,我尝试缩短每个long_strings以查看BCrypt开始能够区分它们的位置,并且我发现如果我将每个长字符串缩短到100个字符左右,最后的尝试('passwor')将开始也是如此.所以现在我不知道该怎么想.

对此有何解释?

ruby encryption passwords integer-overflow bcrypt

4
推荐指数
2
解决办法
1857
查看次数

bcrypt - 跟上摩尔定律

我正在使用bcrypt在我的数据库中存储密码,使用工作因子7,在我合理的现代笔记本电脑上使用大约0.02秒来散列单个密码.

Coda Hale表示,使用bcrypt可以让你通过调整工作因素来"跟上摩尔定律".但是没有办法重新加密用户的密码,因为我没有存储明文.如何让我的数据库保持最新并且难以破解(假设它会延续5年以上,这将成为一个问题)?

passwords cryptography bcrypt

4
推荐指数
1
解决办法
875
查看次数

与BCrypt.net合作

我正在使用自定义会员系统ASP.NET MVC3(在此解释).我想用BCrypt.我的问题是BCrypt.net论证范围.即可以散列它的字符串的最小和最大长度BCrypt,最小/最大长度salt,以及输出字符串的长度.我现在真的在创建数据库,我想知道如何在db中设置密码列.即nvarchar(256)或其他什么?

security bcrypt c#-4.0 asp.net-mvc-3 bcrypt.net

4
推荐指数
1
解决办法
1974
查看次数

用CakePHP和河豚改变密码

我正在尝试设置一个表单,允许用户使用CakePHP 2.3更改密码.使用的算法是河豚.我有以下三个字段:

<?php echo $this->Form->input('old_password', array('type' => 'password', 'autocomplete' => 'off')); ?>
<?php echo $this->Form->input('new_password', array('type' => 'password', 'autocomplete' => 'off')); ?>
<?php echo $this->Form->input('new_password_confirm', array('type' => 'password', 'autocomplete' => 'off', 'label' => 'Confirm Password')); ?>
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试验证他们正确输入旧密码的代码:

$hash = Security::hash($this->request->data['User']['old_password'], 'blowfish');
$correct = $this->User->find('first', array(
    'conditions' => array(
        'User.id' => AuthComponent::user('id'),
        'User.password' => $hash
    ),
    'fields' => array('id')
));
Run Code Online (Sandbox Code Playgroud)

问题是即使我正确输入旧密码,Cake也找不到用户,因为它似乎没有计算正确的哈希值.每次我使用相同的旧密码提交表单时,Cake每次都会生成一个不同的哈希值.这可能是由于我对blowfish/bcrypt算法的工作方式缺乏了解,但我似乎无法弄明白.

我在这里错过了什么?

cakephp blowfish bcrypt cakephp-2.0

4
推荐指数
1
解决办法
2980
查看次数

将密码哈希从SHA转换为bcrypt

这个问题已在Stack Overflow问题中得到解答,但它并不是Grails特有的,也有点模糊.

我使用Spring Security设置我的Grails应用程序,但显然没有获得最新版本,因为它默认为SHA-256而不是bcrypt.现在我的生产数据带有密码哈希,这似乎是一种不太理想的方法.

启用 bcrypt哈希是一块蛋糕:

Config.groovy > grails.plugins.springsecurity.password.algorithm = 'bcrypt'
Run Code Online (Sandbox Code Playgroud)

但现在我需要应用程序将旧哈希转换为新哈希.从根本上说,我了解当用户登录时,我应该让应用程序检查密码是否为SHA-256哈希值,如果是,则使用bcrypt重新哈希输入的密码.过了一会儿,他们都会升级,代码可以删除.

但是,确定密码哈希值是来自SHA-256还是bcrypt的实际代码是什么?

编辑

也就是说,我调用哈希的实际函数是什么?如何bcrypt(incomingpassword)查看它是否与现有密码哈希匹配?

grails spring-security bcrypt jbcrypt

4
推荐指数
1
解决办法
1733
查看次数

如何在Google App Engine(GAE)上使用bcrypt?

我找到了一个python的bcrypt库,看起来很容易使用:

安装它并在我的本地机器上测试hello world示例之后似乎都很好:

>>> import bcrypt
>>> password = b"super secret password"
>>> # Hash a password for the first time, with a certain number of rounds
>>> hashed = bcrypt.hashpw(password, bcrypt.gensalt(10))
>>> # Check that a unhashed password matches one that has previously been
>>> #   hashed
>>> if bcrypt.hashpw(password, hashed) == hashed:
...     print("It Matches!")
... else:
...     print("It Does not Match :(")
Run Code Online (Sandbox Code Playgroud)

但是,在我的GAE应用程序中,当我使用时,import bcrypt我收到错误:

Traceback (most recent call last):
  File "/home/pedro/google_appengine/google/appengine/runtime/wsgi.py", line 239, …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine password-protection bcrypt

4
推荐指数
1
解决办法
2221
查看次数

Docker中的Bcrypt安装失败

我创建了一个在Docker中运行的MongoDB节点应用程序.它工作正常,直到我包含node.bcrypt.js.这使得与节点崩溃node-gyp和bcrypt.

该应用程序在本地和Heroku上运行良好.

我尝试安装一些我在网上找到的建议包,根据错误消息已知需要这些包.这就是为什么我添加了一些额外的依赖项,请参阅node-gyp下面的dockerfile中的相关行.

现在它已经到了我找不到更多建议的地方,但它仍然无法正常工作.我觉得它在本地和Heorku上工作很奇怪,但在Docker上却没有,因此它是我所缺少的.

提前致谢.

错误:

> crowdshelf-server@1.0.0 start /server
> node index.js

  COPY Release/bcrypt_lib.node
make: Leaving directory `/server/node_modules/bcrypt/build'
module.js:338
    throw err;
          ^
Error: Cannot find module './lib/topologies/server'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/server/node_modules/mongodb/node_modules/mongodb-core/index.js:3:13)
    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)

npm ERR! Linux 3.13.0-58-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm …
Run Code Online (Sandbox Code Playgroud)

bcrypt node.js docker

4
推荐指数
1
解决办法
6851
查看次数

MEAN App错误预期对象

我正在尝试编写一个平均身份验证应用程序.现在我可以通过postman在mongodb中创建用户,但是当我尝试对其进行身份验证时,如果它有错误的用户名或密码,则会提供正确的反馈,错误的密码等,但如果它与数据库上的正确用户名和密码匹配,服务器关闭,则不会给出关于邮递员的任何反馈,它在服务器终端上给出以下错误:

(node:11262) DeprecationWarning: Mongoose: mpromise (mongoose's 
default promise library) is deprecated, plug in your own promise 
library instead: http://mongoosejs.com/docs/promises.html
/home/cagdas/Desktop/basictest/node_modules/jsonwebtoken/sign.js:90
throw err;
^

Error: Expected object
    at validate 
(/home/cagdas/Desktop/basictest/node_modules/jsonwebtoken
/sign.js:35:11) at Object.module.exports [as sign] 
(/home/cagdas/Desktop/basictest/node_modules/jsonwebtoken
/sign.js:101:7) at User.comparePassword 
(/home/cagdas/Desktop/basictest/routes/users.js:40:26)
at bcrypt.compare (/home/cagdas/Desktop/basictest/models/user.js:52:6)
at 
/home/cagdas/Desktop/basictest/node_modules/bcryptjs/dist
/bcrypt.js:297:21
at /home/cagdas/Desktop/basictest/node_modules
/bcryptjs/dist/bcrypt.js:1353:21
at Immediate.next (/home/cagdas/Desktop/basictest/node_modules
/bcryptjs/dist/bcrypt.js:1233:21)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:app.js:

const express = require('express') ;
const path = require('path');
const bodyParser = require('body-parser');
const cors = …
Run Code Online (Sandbox Code Playgroud)

javascript bcrypt mongodb jwt mean-stack

4
推荐指数
1
解决办法
1215
查看次数

属性“密码”在文档类型上不存在

我收到此错误文档类型上不存在属性“密码”。那么谁能说出我的代码是否有问题?

const userSchema = new mongoose.Schema({
  email: { type: String, required: true, unique: true },
  password: { type: String, required: true },
  name: { type: String, required: true }
});

userSchema.pre("save", function save(next) {
  const user = this;
  if (!user.isModified("password")) {
    return next();
  }
  bcrypt.genSalt(10, (err, salt) => {
    if (err) {
      return next(err);
    }
    bcrypt.hash(user.password, salt, (err: mongoose.Error, hash) => {
      if (err) {
        return next(err);
      }
      user.password = hash;
      next();
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

bcrypt mongoose typescript

4
推荐指数
3
解决办法
924
查看次数