fix PAT array split

This commit is contained in:
Pascal Fischer 2023-03-16 16:59:32 +01:00
parent 453643683d
commit 628a201e31
2 changed files with 7 additions and 6 deletions

View File

@ -1127,8 +1127,8 @@ func (am *DefaultAccountManager) GetAccountFromPAT(token string) (*Account, *Use
if prefix != PATPrefix {
return nil, nil, fmt.Errorf("token invalid")
}
secret := token[len(PATPrefix):len(PATPrefix)]
encodedChecksum := token[34:40]
secret := token[len(PATPrefix) : len(PATPrefix)+PATsecretLength]
encodedChecksum := token[len(PATPrefix)+PATsecretLength : len(PATPrefix)+PATsecretLength+PATChecksumLength]
verificationChecksum, err := base62.Decode(encodedChecksum)
if err != nil {

View File

@ -13,9 +13,10 @@ import (
const (
// PATPrefix is the globally used, 4 char prefix for personal access tokens
PATPrefix = "nbp_"
secretLength = 30
PATLength = 40
PATPrefix = "nbp_"
PATsecretLength = 30
PATLength = 40
PATChecksumLength = 6
)
// PersonalAccessToken holds all information about a PAT including a hashed version of it for verification
@ -50,7 +51,7 @@ func CreateNewPAT(description string, expirationInDays int, createdBy string) (*
}
func generateNewToken() (string, string, error) {
secret, err := b.Random(secretLength)
secret, err := b.Random(PATsecretLength)
if err != nil {
return "", "", err
}