This commit is contained in:
Mike Schwörer 2022-12-24 03:11:09 +01:00
parent 1a1cd6d0aa
commit aeded3fb37
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF

View File

@ -245,6 +245,35 @@ func (ph PassHash) WithTOTP(totpSecret []byte) (PassHash, error) {
return "", errors.New("unknown version")
}
func (ph PassHash) Change(newPlainPass string) (PassHash, error) {
version, _, _, hastotp, totpsecret, valid := ph.Data()
if !valid {
return "", errors.New("invalid PassHash")
}
if version == 0 {
return HashPasswordV0(newPlainPass)
}
if version == 1 {
return HashPasswordV1(newPlainPass)
}
if version == 2 {
return HashPasswordV2(newPlainPass)
}
if version == 3 {
return HashPasswordV3(newPlainPass, langext.Conditional(hastotp, totpsecret, nil))
}
if version == 4 {
return HashPasswordV4(newPlainPass, langext.Conditional(hastotp, totpsecret, nil))
}
return "", errors.New("unknown version")
}
func (ph PassHash) String() string {
return string(ph)
}