mirror of https://github.com/jetkvm/kvm.git
Merge 760dc494d4
into f3b4dbce49
This commit is contained in:
commit
0ed3963c9f
9
web.go
9
web.go
|
@ -242,6 +242,7 @@ func handleCreatePassword(c *gin.Context) {
|
||||||
// We only allow users with noPassword mode to set a new password
|
// We only allow users with noPassword mode to set a new password
|
||||||
// Users with password mode are not allowed to set a new password without providing the old password
|
// Users with password mode are not allowed to set a new password without providing the old password
|
||||||
// We have a PUT endpoint for changing the password, use that instead
|
// We have a PUT endpoint for changing the password, use that instead
|
||||||
|
|
||||||
if config.LocalAuthMode != "noPassword" {
|
if config.LocalAuthMode != "noPassword" {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Password mode is not enabled"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Password mode is not enabled"})
|
||||||
return
|
return
|
||||||
|
@ -253,7 +254,12 @@ func handleCreatePassword(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(req.Password), bcrypt.DefaultCost)
|
truncatedPassword := req.Password
|
||||||
|
if len(truncatedPassword) > 70 {
|
||||||
|
truncatedPassword = truncatedPassword[:70]
|
||||||
|
}
|
||||||
|
|
||||||
|
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(truncatedPassword), bcrypt.DefaultCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to hash password"})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to hash password"})
|
||||||
return
|
return
|
||||||
|
@ -267,7 +273,6 @@ func handleCreatePassword(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the cookie
|
|
||||||
c.SetCookie("authToken", config.LocalAuthToken, 7*24*60*60, "/", "", false, true)
|
c.SetCookie("authToken", config.LocalAuthToken, 7*24*60*60, "/", "", false, true)
|
||||||
|
|
||||||
c.JSON(http.StatusCreated, gin.H{"message": "Password set successfully"})
|
c.JSON(http.StatusCreated, gin.H{"message": "Password set successfully"})
|
||||||
|
|
Loading…
Reference in New Issue