mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 11:12:44 +01:00
add autogeneration of SCRAM credentials on successful PLAIN
This commit is contained in:
parent
d8dc24dee8
commit
4dd9af8f06
@ -1113,6 +1113,11 @@ func (am *AccountManager) checkPassphrase(accountName, passphrase string) (accou
|
||||
if passwd.CompareHashAndPassword(account.Credentials.PassphraseHash, []byte(passphrase)) != nil {
|
||||
err = errAccountInvalidCredentials
|
||||
}
|
||||
if err == nil && account.Credentials.SCRAMCreds.Iters == 0 {
|
||||
// XXX: if the account was created prior to 2.8, it doesn't have SCRAM credentials;
|
||||
// since we temporarily have access to a valid plaintext password, create them:
|
||||
am.rehashPassword(account.Name, passphrase)
|
||||
}
|
||||
case -1:
|
||||
err = am.checkLegacyPassphrase(migrations.CheckAthemePassphrase, accountName, account.Credentials.PassphraseHash, passphrase)
|
||||
case -2:
|
||||
@ -1132,13 +1137,17 @@ func (am *AccountManager) checkLegacyPassphrase(check migrations.PassphraseCheck
|
||||
return errAccountInvalidCredentials
|
||||
}
|
||||
// re-hash the passphrase with the latest algorithm
|
||||
err = am.setPassword(account, passphrase, true)
|
||||
if err != nil {
|
||||
am.server.logger.Error("internal", "could not upgrade user password", err.Error())
|
||||
}
|
||||
am.rehashPassword(account, passphrase)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (am *AccountManager) rehashPassword(accountName, passphrase string) {
|
||||
err := am.setPassword(accountName, passphrase, true)
|
||||
if err != nil {
|
||||
am.server.logger.Error("internal", "could not upgrade user password", accountName, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (am *AccountManager) loadWithAutocreation(accountName string, autocreate bool) (account ClientAccount, err error) {
|
||||
account, err = am.LoadAccount(accountName)
|
||||
if err == errAccountDoesNotExist && autocreate {
|
||||
|
Loading…
Reference in New Issue
Block a user