5.gin-gorm密码加密
2023-02-13 00:00:05
技术
通过gin-gorm之项目学习
部分的学习,可以对项目的架构有深入的了解 🤟
{% post_link "gin-gorm1项目准备初始化" %}
{% post_link "gin-gorm2数据库" %}
{% post_link "gin-gorm3错误处理与路由接口" %}
{% post_link "gin-gorm4用户模块接口编写" %}
{% post_link "gin-gorm5密码加密" %}
{% post_link "gin-gorm6编辑、删除用户" %}
密码加密
普通级 单向哈希
进阶级 bcrypt-加盐
专家级 scrypt-某黑客写的,目前没有破解方法
// 密码加密
func ScryptPassword(password string) string {
const KeyLen = 10 //长度
salt := make([]byte, 8)
salt = []byte{12, 22, 111, 46, 82, 3, 7, 21}
HashPw, err := scrypt.Key([]byte(password), salt, 16384, 8, 1, KeyLen)
if err != nil {
log.Fatal(err)
}
finalPw := base64.StdEncoding.EncodeToString(HashPw)
return finalPw
}
在添加用户时,将用户的密码进行scrypt加密
data.Password = ScryptPassword(data.Password)