Skip to content

Commit 72e3b9e

Browse files
committed
Format password hash.
1 parent 4a6db19 commit 72e3b9e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func migrateUsers() {
259259
user.IsActive,
260260
user.Email,
261261
user.EmailVerified,
262-
user.PasswordHash,
262+
migratePassword(user.PasswordHash),
263263
user.Note,
264264
)
265265
if err != nil {
@@ -1095,3 +1095,21 @@ func (l *GPSPoint) Scan(src interface{}) error {
10951095
_, err := fmt.Sscanf(string(b), "(%f,%f)", &l.Latitude, &l.Longitude)
10961096
return err
10971097
}
1098+
1099+
func migratePassword(s string) string {
1100+
// old:
1101+
// PBKDF2$sha512$1$l8zGKtxRESq3PA2kFhHRWA==$H3lGMxOt55wjwoc+myeOoABofJY9oDpldJa7fhqdjbh700V6FLPML75UmBOt9J5VFNjAL1AvqCozA1HJM0QVGA==
1102+
1103+
// new:
1104+
// $pbkdf2-sha512$i=1,l=64$l8zGKtxRESq3PA2kFhHRWA$H3lGMxOt55wjwoc+myeOoABofJY9oDpldJa7fhqdjbh700V6FLPML75UmBOt9J5VFNjAL1AvqCozA1HJM0QVGA
1105+
if s == "" {
1106+
return s
1107+
}
1108+
1109+
parts := strings.SplitN(s, "$", 5)
1110+
if len(parts) != 5 {
1111+
panic("Invalid password hash " + s)
1112+
}
1113+
1114+
return fmt.Sprintf("$pbkdf2-%s$i=$%s,l=16$%s$%s", parts[1], parts[2], parts[3], parts[4])
1115+
}

0 commit comments

Comments
 (0)