MCPcopy Create free account
hub / github.com/foxcpp/maddy / VerifyPassword

Method VerifyPassword

internal/auth/shadow/verify.go:51–74  ·  view source on GitHub ↗
(pass string)

Source from the content-addressed store, hash-verified

49}
50
51func (e *Entry) VerifyPassword(pass string) (err error) {
52 // Do not permit null and locked passwords.
53 if e.Pass == "" {
54 return errors.New("verify: null password")
55 }
56 if e.Pass[0] == '!' {
57 return errors.New("verify: locked password")
58 }
59
60 // crypt.NewFromHash may panic on unknown hash function.
61 defer func() {
62 if rcvr := recover(); rcvr != nil {
63 err = fmt.Errorf("%v", rcvr)
64 }
65 }()
66
67 if err := crypt.NewFromHash(e.Pass).Verify(e.Pass, []byte(pass)); err != nil {
68 if errors.Is(err, crypt.ErrKeyMismatch) {
69 return ErrWrongPassword
70 }
71 return err
72 }
73 return nil
74}

Callers 2

AuthPlainMethod · 0.80
mainFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected