mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-05-24 00:24:06 +03:00
Add support for password hashes as an optional alternative to plaintext passwords (#216)
This commit is contained in:
parent
29b017f277
commit
2c2db61158
8 changed files with 67 additions and 10 deletions
|
@ -51,7 +51,18 @@ func Login(db store.IStore) echo.HandlerFunc {
|
|||
}
|
||||
|
||||
userCorrect := subtle.ConstantTimeCompare([]byte(user.Username), []byte(dbuser.Username)) == 1
|
||||
passwordCorrect := subtle.ConstantTimeCompare([]byte(user.Password), []byte(dbuser.Password)) == 1
|
||||
|
||||
var passwordCorrect bool
|
||||
if dbuser.PasswordHash != "" {
|
||||
match, err := util.VerifyHash(dbuser.PasswordHash, user.Password)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "Cannot verify password"})
|
||||
}
|
||||
passwordCorrect = match
|
||||
} else {
|
||||
passwordCorrect = subtle.ConstantTimeCompare([]byte(user.Password), []byte(dbuser.Password)) == 1
|
||||
}
|
||||
|
||||
if userCorrect && passwordCorrect {
|
||||
// TODO: refresh the token
|
||||
sess, _ := session.Get("session", c)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue