Update web.go

made changes to truncate to 70 characters
This commit is contained in:
Srujan S 2025-01-10 19:18:32 -06:00 committed by GitHub
parent 8ffe66a1bc
commit 760dc494d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 34 additions and 29 deletions

9
web.go
View File

@ -235,6 +235,7 @@ func handleCreatePassword(c *gin.Context) {
// 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
// We have a PUT endpoint for changing the password, use that instead
if config.LocalAuthMode != "noPassword" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Password mode is not enabled"})
return
@ -246,7 +247,12 @@ func handleCreatePassword(c *gin.Context) {
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 {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to hash password"})
return
@ -260,7 +266,6 @@ func handleCreatePassword(c *gin.Context) {
return
}
// Set the cookie
c.SetCookie("authToken", config.LocalAuthToken, 7*24*60*60, "/", "", false, true)
c.JSON(http.StatusCreated, gin.H{"message": "Password set successfully"})