Skip to content

Commit

Permalink
Hash password on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-WWU-IT committed Aug 2, 2021
1 parent 66b146b commit 97d9e99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/siteacc/html/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const panelTemplate = `
var msgBuffer = new TextEncoder().encode(this);
var hashBuffer = await crypto.subtle.digest("SHA-256", msgBuffer);
var hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase();
};
$(CONTENT_JAVASCRIPT)
Expand Down
6 changes: 6 additions & 0 deletions pkg/siteacc/manager/accmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package manager

import (
"crypto/sha256"
"fmt"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -204,6 +206,10 @@ func (mngr *AccountsManager) ResetPassword(name string) error {
mngr.sendEmail(accountUpd, nil, email.SendPasswordReset)
}

// Passwords are transferred as lower-case SHA256 hashes, so update the password accordingly
accountUpd.Password.Value = fmt.Sprintf("%x", sha256.Sum256([]byte(accountUpd.Password.Value)))
err = mngr.UpdateAccount(accountUpd, true, false)

return err
}

Expand Down

0 comments on commit 97d9e99

Please sign in to comment.