MCPcopy
hub / github.com/dgraph-io/dgraph / Encrypt

Function Encrypt

types/password.go:18–29  ·  view source on GitHub ↗

Encrypt encrypts the given plain-text password.

(plain string)

Source from the content-addressed store, hash-verified

16
17// Encrypt encrypts the given plain-text password.
18func Encrypt(plain string) (string, error) {
19 if len(plain) < pwdLenLimit {
20 return "", errors.Errorf("Password too short, i.e. should have at least 6 chars")
21 }
22
23 encrypted, err := bcrypt.GenerateFromPassword([]byte(plain), bcrypt.DefaultCost)
24 if err != nil {
25 return "", err
26 }
27
28 return string(encrypted), nil
29}
30
31// VerifyPassword checks that the plain-text password matches the encrypted password.
32func VerifyPassword(plain, encrypted string) error {

Callers 2

ConvertFunction · 0.85
TestEncryptFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by 1

TestEncryptFunction · 0.68