久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 Node.js 和 MongoDB 存儲密碼

Storing passwords with Node.js and MongoDB(使用 Node.js 和 MongoDB 存儲密碼)
本文介紹了使用 Node.js 和 MongoDB 存儲密碼的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在尋找一些如何使用 node.js 和 mongodb 安全存儲密碼和其他敏感數據的示例.

I'm looking for some examples of how to securely store passwords and other sensitive data using node.js and mongodb.

我希望所有內容都使用唯一的鹽,我將在 mongo 文檔中與哈希一起存儲.

I want everything to use a unique salt that I will store along side the hash in the mongo document.

對于身份驗證,我是否必須對輸入進行加鹽和加密并將其與存儲的哈希匹配?

For authentication do I have to just salt and encrypt the input and match it to a stored hash?

我是否需要解密這些數據?如果需要,我應該怎么做?

Should I ever need to decrypt this data and if so how should I do it?

私鑰,甚至加鹽方法如何安全地存儲在服務器上?

How are the private keys, or even salting methods securely stored on the server?

我聽說 AES 和 Blowfish 都是不錯的選擇,我應該使用什么?

I've heard the AES and Blowfish are both good options, what should I use?

任何有關如何設計的示例都會非常有幫助!

謝謝!

推薦答案

使用這個:https://github.com/ncb000gt/node.bcrypt.js/

bcrypt 是少數幾個專注于這個用例的算法之一.您永遠無法解密您的密碼,只能驗證用戶輸入的明文密碼是否與存儲/加密的哈希值匹配.

bcrypt is one of just a few algorithms focused on this use case. You should never be able to decrypt your passwords, only verify that a user-entered cleartext password matches the stored/encrypted hash.

bcrypt 使用起來非常簡單.這是我的 Mongoose 用戶模式的一個片段(在 CoffeeScript 中).請務必使用異步函數,因為 bycrypt 很慢(故意).

bcrypt is very straightforward to use. Here is a snippet from my Mongoose User schema (in CoffeeScript). Be sure to use the async functions as bycrypt is slow (on purpose).

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

另外,請閱讀 這篇文章,它應該讓你相信 bcrypt 是一個很好的選擇并幫助您避免變得真正有效".

Also, read this article, which should convince you that bcrypt is a good choice and help you avoid becoming "well and truly effed".

這篇關于使用 Node.js 和 MongoDB 存儲密碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應)
Check if user ID exists in Discord server(檢查 Discord 服務器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創建我的第一個機器人,但總是錯誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機器人編寫事件/命令處理程序?)
How to find a User ID from a Username in Discord.js?(如何從 Discord.js 中的用戶名中查找用戶 ID?)
主站蜘蛛池模板: 黄色av大片| 亚洲在线 | 蜜桃视频麻豆 | 日本久久综合网 | 久久久久99 | 日韩精品一区二区三区四区 | 久久成人在线视频 | 欧美一级欧美一级在线播放 | 欧美一区二区二区 | av免费看在线 | 国产精品视频一二三区 | 国产精品久久久久久久久久久久午夜片 | 国产一区二区精品自拍 | 日日操夜夜操天天操 | 久久久久国产精品午夜一区 | 蜜桃视频一区二区三区 | www免费视频| 日韩精品1区2区3区 国产精品国产成人国产三级 | 一区精品视频在线观看 | 日日夜夜影院 | 九九九视频在线 | 久久男人天堂 | 北条麻妃一区二区三区在线观看 | 中文福利视频 | 国产一区日韩在线 | 亚洲a在线观看 | 放个毛片看看 | www4虎| 久久国产精彩视频 | 可以在线看的黄色网址 | 91精品国产高清一区二区三区 | 国产一区二区 | 日本又色又爽又黄又高潮 | 亚洲精品欧美一区二区三区 | 91大片| 性色综合 | 中文无吗| av一级| 亚洲精品免费在线观看 | 亚洲精品日韩精品 | 欧美日韩高清免费 |