WIP: Add users system, required for uploading new pastes #77
@ -89,13 +89,14 @@ func HashPassword(password string) (string, error) {
|
||||
return fmt.Sprintf("$%s$%s$%s$%s", pwdAlgo, pwdParams, encodedSalt, encodedHash), nil
|
||||
yorick marked this conversation as resolved
|
||||
}
|
||||
|
||||
var errInvalidDBPasswordFormat = errors.New("invalid password format in db")
|
||||
func comparePassword(hashedPassword string, password string) (bool, error) {
|
||||
// Extract the salt and hash from the hashed password string
|
||||
yorick marked this conversation as resolved
mrngm
commented
It's not safe to do a slice expression that requires at least two returned elements on a function that may return an empty slice, or a slice of length one. It's not safe to do a slice expression that requires at least two returned elements on a function that may return an empty slice, or a slice of length one.
|
||||
fields := strings.Split(hashedPassword, "$")[1:]
|
||||
if len(fields) != 4 || fields[0] != pwdAlgo || fields[1] != pwdParams {
|
||||
return false, errors.New("invalid password format in db")
|
||||
fields := strings.Split(hashedPassword, "$")
|
||||
if len(fields) != 5 || fields[1] != pwdAlgo || fields[2] != pwdParams {
|
||||
yorick marked this conversation as resolved
mrngm
commented
(another option: add (another option: add `var errInvalidDBPasswordFormat = errors.New("invalid password format in db")` in the global scope, and return that here. Works nice with `errors.Is(err, errInvalidDBPasswordFormat), as I suppose we want to log such occurrences)
|
||||
return false, errInvalidDBPasswordFormat
|
||||
}
|
||||
encodedSalt, encodedHash := fields[2], fields[3]
|
||||
encodedSalt, encodedHash := fields[3], fields[4]
|
||||
|
||||
// Decode the salt and hash from base64
|
||||
yorick marked this conversation as resolved
mrngm
commented
(See comment above on (See comment above on `RawURLEncoding`)
|
||||
salt, err := base64.RawStdEncoding.DecodeString(encodedSalt)
|
||||
|
Loading…
Reference in New Issue
Block a user
Is there a specific reason you omitted the (optional) field
version
? Theargon2
package defines one, so it seems a good idea to include that as well.