| 75 | } |
| 76 | |
| 77 | func NewUserWithPasswordHash(phone, email, passwordHash, aud string, userData map[string]interface{}) (*User, error) { |
| 78 | if strings.HasPrefix(passwordHash, crypto.Argon2Prefix) { |
| 79 | _, err := crypto.ParseArgon2Hash(passwordHash) |
| 80 | if err != nil { |
| 81 | return nil, err |
| 82 | } |
| 83 | } else if strings.HasPrefix(passwordHash, crypto.FirebaseScryptPrefix) { |
| 84 | _, err := crypto.ParseFirebaseScryptHash(passwordHash) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | } else { |
| 89 | // verify that the hash is a bcrypt hash |
| 90 | _, err := bcrypt.Cost([]byte(passwordHash)) |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | } |
| 95 | id := uuid.Must(uuid.NewV4()) |
| 96 | user := &User{ |
| 97 | ID: id, |
| 98 | Aud: aud, |
| 99 | Email: storage.NullString(strings.ToLower(email)), |
| 100 | Phone: storage.NullString(phone), |
| 101 | UserMetaData: userData, |
| 102 | EncryptedPassword: &passwordHash, |
| 103 | } |
| 104 | return user, nil |
| 105 | } |
| 106 | |
| 107 | // NewUser initializes a new user from an email, password and user data. |
| 108 | func NewUser(phone, email, password, aud string, userData map[string]interface{}) (*User, error) { |