bcrypt

web前端 | 博客(二)登录功能

扶醉桌前 提交于 2020-01-06 20:29:47
实现登录功能 创建用户集合,初始化用户 连接数据库 创建用户集合 初始化用户 为登录表单项设置请求地址,请求方式(GET方法会将参数放到地址栏中,不隐蔽,要用POST方法,它将参数放到消息体中,比较隐蔽)以及表单name属性 当用户点击登录按钮时,客户端验证用户是否填写了登录表单 如果其中一项没有输入,则阻止表单提交 服务器端请求接收参数,验证用户是否填写了登录表单(有时候客户端的js代码会被禁用,无法正确识别表单的准确性,故服务端的表单验证必不可少) 如果有一项没有输入,为客户端做出响应,阻止程序向下执行(例如,如果没有填写邮箱,则找不到该用户)(无论邮箱地址错误还是密码错误,一律提示两者都错,防止用户恶意猜出其他用户的账号密码) 根据邮箱地址查询用户信息 如果用户不存在,为客户端做出响应 如果用户存在,将用户名和密码进行比对 比对成功,则用户登录成功 比对失败,则则用户登录失败 数据库 数据库连接 在model中新建connect.js和user.js,分别用于数据库连接和创建用户集合。 connect.js //连接数据库 //引入mongoose第三方模块,这个对象下面有个connect方法用户连接数据库 const mongoose = require ( 'mongoose' ) ; //连接数据库 mongoose . connect ( 'mongodb:/

Security of bcrypt iterations/cost parameter

五迷三道 提交于 2020-01-06 15:48:10
问题 Fact A. Based on Pigeonhole Principle, every hash functions has infinite number of collisions, even if none is found yet. Fact B. Re-hashing a hash, like hash(hash(password)) is not more secure than hash(password), actually hash(hash(password)) open up a collision attack that is not possible with hash(password). Fact C. Based on B, by increasing iterations, we reach a point that most passwords and salts will return same constant hash value. I mean probability of colliding will be high, even

bcrypt generates incorrect hashes - is my user-input processing correct?

心不动则不痛 提交于 2020-01-06 06:09:51
问题 I've written a short program in Go to generate a bcrypt password hash from a password provided via stdin. Minimal example below: package main import ( "bufio" "fmt" "golang.org/x/crypto/bcrypt" ) func main() { fmt.Println("Enter password:") reader := bufio.NewReader(os.Stdin) inputPassword, _ := reader.ReadString('\n') inputPasswordBytes := []byte(inputPassword) hashBytes, _ := bcrypt.GenerateFromPassword(inputPasswordBytes, bcrypt.DefaultCost) hashStr := string(hashBytes) fmt.Println(hashStr

Node.JS Schema.pre('save) is not changing data

偶尔善良 提交于 2020-01-04 06:26:52
问题 I'm making user authorization system and want to hash password before save it to DB. To reach this i use bcrypt-nodejs. The question in title above; var mongoose = require('mongoose'); var bcrypt = require('bcrypt-nodejs'); var userSchema = new mongoose.Schema({ email: { type: String, unique: true, required: true, }, username: { type: String, unique: true, required: true }, password: { type: String, unique: true, required: true } }); userSchema.pre('save', (next) => { var user = this; bcrypt

Why does Ruby's bcrypt lib include the salt in plaintext in the hash? [duplicate]

社会主义新天地 提交于 2020-01-03 16:59:53
问题 This question already has answers here : How can bcrypt have built-in salts? (3 answers) Do I need to store the salt with bcrypt? (1 answer) Closed 5 years ago . I am using Coda Hale's Ruby bcrypt library. I noticed recently that it wasn't working like I thought it worked. I had thought that the proper procedure is: Generate a salt Obtain a password Concatenate the salt and the password strings Hash them through your hashing function But when I look at the results of the bcrypt function it

Are Rails passwords generated with bcrypt portable?

99封情书 提交于 2020-01-03 14:09:26
问题 I have an existing web application with a few thousand users which I'm porting over to Rails. As I rewrite and refactor this app I may need to run it on any number of different servers for development, testing, and production purposes. I'm using Rails' built-in has_secure_password method in my user model but I'm concerned about the portability of password data. I will need to move the contents of my database from machine to machine to test in different environments and its very important that

Rails Fixtures with BCrypt

血红的双手。 提交于 2020-01-03 08:07:09
问题 I'm having a problem with fixtures for BCrypt password: my User model is both setup with has_secure_password and validates_presence_of :password . The point is that BCrypt uses password and password_confirmation but in the schema there is only the password_digest field. The fixture is complaining that the password field does not exists. How can I avoid this? Thank you 回答1: Seems that fixtures are being pushed to the database directly. That means that instead of password: you need password

How to use Bcrypt to encrypt passwords in Django

China☆狼群 提交于 2020-01-02 04:00:47
问题 I am trying to use Bcrypt to encrypt passwords that users provide upon registration and then use Bcrypt to validate a password a user provides upon login against the hashed version stored in the database. There is some pretty good documentation about how to install Bcrypt on via the Django docs, but they don't actually show you how to use Bcrypt to hash passwords or use other commands. Do you need to import Brcrypt from somewhere? If so, what is the correct syntax for it? What is the syntax

Changing password with CakePHP and blowfish

最后都变了- 提交于 2020-01-01 12:45:28
问题 I'm trying to set up a form to allow a user to change their password using CakePHP 2.3. The algorithm being used is blowfish. I have the following three fields: <?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

BCryptHelper.CheckPassword always returns false

与世无争的帅哥 提交于 2019-12-31 04:38:07
问题 I'm implementing password hashing using BCrypt, which should be pretty straight forward to use. However when the password is checked against the hashed password using BCryptHelper.CheckPassword(Password, hashedDBPassword) this always return false. Here is my hasher class: public static class BCryptHasher { public static string EncryptPassword(string password) { var passwordToHash = password; var hashedPassword = BCryptHelper.HashPassword(passwordToHash, BCryptHelper.GenerateSalt(6)); return