mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-16 09:36:07 +00:00
fix(db): make password-hash migration idempotent to prevent lock-out (#4612)
The UserPasswordHash seeder bcrypt-hashed user.Password unconditionally, assuming plaintext. If it ran on an already-bcrypt value (DB restore, SQLite<->Postgres switch, history_of_seeders inconsistency on upgrade) it double-hashed the password, locking the admin out with both old and new passwords rejected. Skip any password that is already a bcrypt hash.
This commit is contained in:
@@ -203,6 +203,9 @@ func runSeeders(isUsersEmpty bool) error {
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
if crypto.IsHashed(user.Password) {
|
||||
continue
|
||||
}
|
||||
hashedPassword, err := crypto.HashPasswordAsBcrypt(user.Password)
|
||||
if err != nil {
|
||||
log.Printf("Error hashing password for user '%s': %v", user.Username, err)
|
||||
|
||||
Reference in New Issue
Block a user