sojuctl: change-password: check if user exists

When changing the password, checks if the user exists *before* prompting
for a password change, instead of after.
This commit is contained in:
Kalyan Sriram 2020-11-25 12:08:19 -08:00 committed by Simon Ser
parent cab0fc2b7d
commit 586c7ee336
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
1 changed files with 5 additions and 4 deletions

View File

@ -84,6 +84,11 @@ func main() {
os.Exit(1)
}
user, err := db.GetUser(username)
if err != nil {
log.Fatalf("failed to get user: %v", err)
}
password, err := readPassword()
if err != nil {
log.Fatalf("failed to read password: %v", err)
@ -94,10 +99,6 @@ func main() {
log.Fatalf("failed to hash password: %v", err)
}
user, err := db.GetUser(username)
if err != nil {
log.Fatalf("failed to get user: %v", err)
}
user.Password = string(hashed)
if err := db.StoreUser(user); err != nil {
log.Fatalf("failed to update password: %v", err)