我正在开发一个 Web 应用程序。为了对密码进行哈希处理,我使用了以下逻辑package coreimport ( "math/rand" "golang.org/x/crypto/bcrypt")type User struct { Username string `json:"username"` Password string `json:"password"`}type Hasher interface { HashPassword()}func (u *User) HashPassword() { cost := rand.Intn(28) + 4 //TODO: Handle error hashedPassword, _ := bcrypt.GenerateFromPassword([]byte(u.Password), cost) u.Password = string(hashedPassword)}然后在处理请求时func HandleRegister(w http.ResponseWriter, r *http.Request) { var user core.User var hasher core.Hasher hasher = &user //TODO: Handle error _ = json.NewDecoder(r.Body).Decode(&user) hasher.HashPassword() fmt.Println(user)}出于安全原因,我使用随机成本进行散列。问题是当成本变大时,过程真的很慢。我Postman用来向我的服务器发送请求,但它真的很慢。为什么呢?我的实施错了吗?注意:在我的 SQLite 数据库中,我选择TEXT密码列的类型来存储散列密码。使用BLOBtype 而不是会更好TEXT吗?
- 1 回答
- 0 关注
- 309 浏览
添加回答
举报
0/150
提交
取消
