mirror of
https://github.com/swissmakers/wireguard-manager.git
synced 2026-04-11 13:47:05 +02:00
Add support for password hashes as an optional alternative to plaintext passwords (#216)
This commit is contained in:
committed by
GitHub
parent
29b017f277
commit
2c2db61158
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user