fan*_*ncy 69 javascript cryptography aes mongodb node.js
我正在寻找一些如何使用node.js和mongodb安全地存储密码和其他敏感数据的示例.
我希望一切都使用一个独特的盐,我将存储在mongo文档中的哈希旁边.
对于身份验证,我是否只需对输入进行加密和加密,并将其与存储的哈希相匹配?
我是否需要解密此数据?如果需要,我应该如何解决?
如何将私钥,甚至salting方法安全地存储在服务器上?
我听说AES和Blowfish都是不错的选择,我该怎么用?
任何如何设计这个的例子都会非常有用!
谢谢!
Pet*_*ons 35
使用此:https://github.com/ncb000gt/node.bcrypt.js/
bcrypt是专注于此用例的少数几种算法之一.您永远不能解密密码,只能验证用户输入的明文密码是否与存储/加密的哈希匹配.
bcrypt非常简单易用.这是我的Mongoose User架构的一个片段(在CoffeeScript中).一定要使用async函数,因为bycrypt很慢(故意).
class User extends SharedUser
defaults: _.extend {domainId: null}, SharedUser::defaults
#Irrelevant bits trimmed...
password: (cleartext, confirm, callback) ->
errorInfo = new errors.InvalidData()
if cleartext != confirm
errorInfo.message = 'please type the same password twice'
errorInfo.errors.confirmPassword = 'must match the password'
return callback errorInfo
message = min4 cleartext
if message
errorInfo.message = message
errorInfo.errors.password = message
return callback errorInfo
self = this
bcrypt.gen_salt 10, (error, salt)->
if error
errorInfo = new errors.InternalError error.message
return callback errorInfo
bcrypt.encrypt cleartext, salt, (error, hash)->
if error
errorInfo = new errors.InternalError error.message
return callback errorInfo
self.attributes.bcryptedPassword = hash
return callback()
verifyPassword: (cleartext, callback) ->
bcrypt.compare cleartext, @attributes.bcryptedPassword, (error, result)->
if error
return callback(new errors.InternalError(error.message))
callback null, result
Run Code Online (Sandbox Code Playgroud)
另外,阅读这篇文章,这应该说服你bcrypt是一个很好的选择,并帮助你避免变得"真正和真正有效".
cho*_*ovy 13
这是我迄今为止遇到的最好的例子,使用node.bcrypt.js http://devsmash.com/blog/password-authentication-with-mongoose-and-bcrypt
| 归档时间: |
|
| 查看次数: |
38102 次 |
| 最近记录: |