我一直在做很多关于在数据库中安全存储密码的研究,bcrypt似乎作为最安全的哈希算法之一出现在各地,所以我可能会用它来存储我网站的密码(用 PHP 编写)。它的主要卖点之一似乎是它非常慢,因此有助于减缓暴力/字典攻击。从字面上看,我读过的每一篇文章都提到 bcrypt 的优点,因为它很慢,因此可以防止暴力攻击。
所以,我的问题是:使用 PHP 登录失败后,我不能手动让代码暂停一两秒吗sleep()?为什么 bcrypt 慢如此重要?我的印象是,我可以使用任何加密算法(假设它的加密方式与 bcrypt 一样),在登录失败时添加 PHP sleep(),并且可以很好地防御暴力/字典攻击bcrypt。
我想使用 Go 创建一个用户身份验证系统,但我一直无法登录帐户。我使用 bcrypt 来散列密码而不是将其保存到数据库 (MySQL)。问题显示何时我想将其与插入的密码进行比较。我有这个错误:hashedSecret too short to be a bcrypted password。我不知道我做错了什么。这是我的代码:
models.go
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Password string `json:"password"`
IsAdmin bool `json:"is_admin"`
}
Run Code Online (Sandbox Code Playgroud)
user-routes.go (login func)
err := db.QueryRow("SELECT Password FROM Users WHERE Username = ?", user.Username).Scan(&storedPass)
if err != nil {
log.Fatal(err)
}
// hashed password
fmt.Println(storedPass, []byte(storedPass))
err = bcrypt.CompareHashAndPassword([]byte(storedPass), []byte(user.Password))
if err != nil {
// Here is error
fmt.Println(err.Error())
}
Run Code Online (Sandbox Code Playgroud)
user-routes.go (register func)
stmt, err := …Run Code Online (Sandbox Code Playgroud) 我有一个带有 SQL/Web 依赖项的 Spring Boot 项目。我有控制器和模型,但没有配置类。这是一个非常简单的项目,因此我通过检查请求标头中的特定于用户的令牌来进行简单的身份验证。我想在将密码保存到我的数据库之前使用 BCrypt 依赖来散列密码,但 Spring Boot 不会让我简单地使用静态函数。
我已将这三个依赖项添加到我的 pom.xml 中:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并在我的控制器中创建了一个端点,只是为了检查静态 hashpw 函数的输出。
@GetMapping("/bcrypt/{pw}")
public String crypt(@PathVariable String pw)
{
return BCrypt.hashpw(pw, "xxwv");
}
Run Code Online (Sandbox Code Playgroud)
但是现在我添加了这 3 个依赖项,它不断将我重定向到我从未创建的登录页面。我只想使用静态散列函数,而无需 Spring Boot 添加我从未要求过的随机安全性。
我正在开发一个Node.js需要使用来自Laravel应用程序的相同数据库信息登录的应用程序。
我已经阅读BCrypt并尝试使用它来比较它生成的散列密码与Laravel存储在数据库中的密码。
所以,根据 的文档BCrypt,我需要做这样的事情:
var salt = bcrypt.genSaltSync(saltRounds);
var hash = bcrypt.hashSync(myPlaintextPassword, salt);
Run Code Online (Sandbox Code Playgroud)
但我不知道如何使用完全相同的盐Laravel来散列我的密码。我需要使用APP_KEY来做到这一点吗?
我使用的是 Windows 10(版本 10.0.17763 内部版本 17763)。我正在尝试使用 NPM 通过 Nodejs Express 服务器安装 Bcrypt。我已经更新了最新的 Nodejs 版本(v12.16.3)。无论我安装最新版本的 Bcrypt 还是早期版本,我总是遇到相同的错误:
node-pre-gyp\bin\node-pre-gyp我不知道为什么它在 directoy 中寻找C:\Users\hazzaldo\Desktop\web-dev-udemy-course\。那里没有这样的目录!这只是一个存储我的课程文件的文件夹。
我也不确定为什么会发生这种情况:
-Security\store-confidential-data-web-app\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file
Run Code Online (Sandbox Code Playgroud)
我在其他论坛中查找过此类错误,但没有解决方案对我有帮助。有些是旧论坛,要求安装已弃用的模块。
bcrypt和 之间有什么区别encrypt,以及如何将laravel?\xe2\x80\x8f中的值返回到正常状态
我正在尝试重写最初使用 Spring 开发的应用程序。用户身份验证是通过 Spring Security 提供的,Spring Security 使用 Bcrypt 来生成和检查散列密码。
它们以如下所示的格式存储在数据库中。据我所知,它是这样表示的:
| |RR| Salt | Hashed Password |
$2a$10$Dh23I3CO6l1n3mOofdazreNLg2OHxzDrxyGGZEstTbITKs.cX3N/u
Run Code Online (Sandbox Code Playgroud)
(其中RR是轮数)
我尝试将其迁移到新的表结构,如使用 4.6的哈希密码表示形式下的“表 3. 示例表”中所示。组件文档,例如:
NAME | PASSWORD | SALT |ITERATION_COUNT|
=====|=================================|========================|===============|
test | NLg2OHxzDrxyGGZEstTbITKs.cX3N/u | Dh23I3CO6l1n3mOofdazre | 10 |
Run Code Online (Sandbox Code Playgroud)
我已经配置了映射器,application.properties如下所示:
quarkus.security.jdbc.principal-query.sql=SELECT u.password, u.salt, u.iteration_count FROM test_user u WHERE u.name=?
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.enabled=true
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.password-index=1
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.hash-encoding=base64
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.salt-index=2
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.salt-encoding=base64
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.iteration-count-index=3
Run Code Online (Sandbox Code Playgroud)
但是,我要么收到由无效的 base64 字符引起的错误(这并不完全令人惊讶,因为 Spring Security 中的实现声明它不是 MIME 兼容的 base64 实现),或者当该错误不存在时,它无法验证密码。
我如何才能将所有用户迁移到 Quarkus 使用的 Bcrypt 实现?
这是运行时显示的错误。
\n在 bcrypt 的 GitHub wiki 上,他们说它是 Node-js 的本机模块,并且需要编译器和构建依赖项才能构建。\n我做错了什么,有人可以帮助我吗
\n{\n"errorType": "Error",\n"errorMessage": "/var/task/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: invalid ELF header",\n"stack": [\n "Error: /var/task/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: invalid ELF header",\n " at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)",\n " at Module.load (internal/modules/cjs/loader.js:863:32)",\n " at Function.Module._load (internal/modules/cjs/loader.js:708:14)",\n " at Module.require (internal/modules/cjs/loader.js:887:19)",\n " at require (internal/modules/cjs/helpers.js:74:18)",\n " at Object.<anonymous> (/var/task/node_modules/bcrypt/bcrypt.js6\xef\xb8\x8f\xe2\x83\xa316)",\n " at Module._compile (internal/modules/cjs/loader.js:999:30)",\n " at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",\n " at Module.load (internal/modules/cjs/loader.js:863:32)",\n " at Function.Module._load (internal/modules/cjs/loader.js:708:14)"\n]\nRun Code Online (Sandbox Code Playgroud)\n}
\n我必须安装 bcrypt,但遇到了错误。我尝试了我找到的大部分解决方案。有很多线程,但我在 Mac 上还没有看到很多。\n以下是我从终端得到的内容:
\nyarn install v1.22.11\nwarning ../../../package.json: No license field\ninfo No lockfile found.\n[1/5] Validating package.json...\n[2/5] Resolving packages...\nwarning @types/date-fns@2.6.0: This is a stub types definition for date-fns (https://github.com/date-fns/date-fns). date-fns provides its own type definitions, so you don't need @types/date-fns installed!\nwarning @types/knex@0.16.1: This is a stub types definition. knex provides its own type definitions, so you do not need this installed.\nwarning knex > liftoff > findup-sync > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated\nwarning knex > liftoff > findup-sync …Run Code Online (Sandbox Code Playgroud) bcrypt ×10
node.js ×3
laravel ×2
npm ×2
amazon-ec2 ×1
apple-m1 ×1
encryption ×1
go ×1
hash ×1
heroku ×1
java ×1
javascript ×1
macos ×1
mean-stack ×1
node-gyp ×1
node-pre-gyp ×1
quarkus ×1
security ×1
spring-boot ×1