Compare commits
No commits in common. "d95c7abea46dd84049262571ab9481922e089c33" and "c899c098f62994536f6952626c3feb7e5d041ab7" have entirely different histories.
d95c7abea4
...
c899c098f6
@ -1,10 +1,6 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
import "regexp"
|
||||
|
||||
// Define the regex pattern as a constant
|
||||
const (
|
||||
@ -16,18 +12,3 @@ func IsValidPIN(pin string) bool {
|
||||
match, _ := regexp.MatchString(pinPattern, pin)
|
||||
return match
|
||||
}
|
||||
|
||||
// HashPIN uses bcrypt with 8 salt rounds to hash the PIN
|
||||
func HashPIN(pin string) (string, error) {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(pin), 8)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(hash), nil
|
||||
}
|
||||
|
||||
// VerifyPIN compareS the hashed PIN with the plaintext PIN
|
||||
func VerifyPIN(hashedPIN, pin string) bool {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hashedPIN), []byte(pin))
|
||||
return err == nil
|
||||
}
|
||||
|
@ -356,19 +356,11 @@ func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byt
|
||||
res.FlagReset = append(res.FlagReset, flag_pin_mismatch)
|
||||
} else {
|
||||
res.FlagSet = append(res.FlagSet, flag_pin_mismatch)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Hash the PIN
|
||||
hashedPIN, err := common.HashPIN(string(temporaryPin))
|
||||
// If matched, save the confirmed PIN as the new account PIN
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_ACCOUNT_PIN, []byte(temporaryPin))
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to hash temporaryPin", "error", err)
|
||||
}
|
||||
|
||||
// save the hashed PIN as the new account PIN
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_ACCOUNT_PIN, []byte(hashedPIN))
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to write DATA_ACCOUNT_PIN entry with", "key", common.DATA_ACCOUNT_PIN, "hashedPIN value", hashedPIN, "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed to write temporaryPin entry with", "key", common.DATA_ACCOUNT_PIN, "value", temporaryPin, "error", err)
|
||||
return res, err
|
||||
}
|
||||
return res, nil
|
||||
@ -400,18 +392,11 @@ func (h *Handlers) VerifyCreatePin(ctx context.Context, sym string, input []byte
|
||||
res.FlagSet = append(res.FlagSet, flag_pin_set)
|
||||
} else {
|
||||
res.FlagSet = []uint32{flag_pin_mismatch}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Hash the PIN
|
||||
hashedPIN, err := common.HashPIN(string(temporaryPin))
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_ACCOUNT_PIN, []byte(temporaryPin))
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to hash temporaryPin", "error", err)
|
||||
}
|
||||
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_ACCOUNT_PIN, []byte(hashedPIN))
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to write DATA_ACCOUNT_PIN entry with", "key", common.DATA_ACCOUNT_PIN, "value", hashedPIN, "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed to write temporaryPin entry with", "key", common.DATA_ACCOUNT_PIN, "value", temporaryPin, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user