首页 > 开发 > Python > 正文

Python中,这样加密用户密码,有什么需要改进的?

2017-09-06 19:23:21  来源:网友分享

描述问题

想安全地存储用户密码

上下文环境

  1. Python27

  2. Linux-Server

相关代码

解决方案

最好的方法当然是永远不要decrypt

你看下这里的例子:

https://paragonie.com/blog/20...

import bcryptimport hmac# Calculating a hashpassword = b"correct horse battery staple"hashed = bcrypt.hashpw(password, bcrypt.gensalt())# Validating a hash (don't use ==)if (hmac.compare_digest(bcrypt.hashpw(password, hashed), hashed)):    # Login successful

bcrypt妥妥的