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 { if prefix != PATPrefix {
return nil, nil, fmt.Errorf("token invalid") return nil, nil, fmt.Errorf("token invalid")
} }
secret := token[len(PATPrefix):len(PATPrefix)] secret := token[len(PATPrefix) : len(PATPrefix)+PATsecretLength]
encodedChecksum := token[34:40] encodedChecksum := token[len(PATPrefix)+PATsecretLength : len(PATPrefix)+PATsecretLength+PATChecksumLength]
verificationChecksum, err := base62.Decode(encodedChecksum) verificationChecksum, err := base62.Decode(encodedChecksum)
if err != nil { if err != nil {

View File

@ -14,8 +14,9 @@ import (
const ( const (
// PATPrefix is the globally used, 4 char prefix for personal access tokens // PATPrefix is the globally used, 4 char prefix for personal access tokens
PATPrefix = "nbp_" PATPrefix = "nbp_"
secretLength = 30 PATsecretLength = 30
PATLength = 40 PATLength = 40
PATChecksumLength = 6
) )
// PersonalAccessToken holds all information about a PAT including a hashed version of it for verification // 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) { func generateNewToken() (string, string, error) {
secret, err := b.Random(secretLength) secret, err := b.Random(PATsecretLength)
if err != nil { if err != nil {
return "", "", err return "", "", err
} }