(username, password string, hashAlgo string, opts HashOpts)
| 118 | } |
| 119 | |
| 120 | func (a *Auth) CreateUserHash(username, password string, hashAlgo string, opts HashOpts) error { |
| 121 | tbl, ok := a.table.(module.MutableTable) |
| 122 | if !ok { |
| 123 | return fmt.Errorf("%s: table is not mutable, no management functionality available", a.modName) |
| 124 | } |
| 125 | |
| 126 | if _, ok := HashCompute[hashAlgo]; !ok { |
| 127 | return fmt.Errorf("%s: unknown hash function: %v", a.modName, hashAlgo) |
| 128 | } |
| 129 | |
| 130 | key, err := precis.UsernameCaseMapped.CompareKey(username) |
| 131 | if err != nil { |
| 132 | return fmt.Errorf("%s: create user %s (raw): %w", a.modName, username, err) |
| 133 | } |
| 134 | |
| 135 | _, ok, err = tbl.Lookup(context.TODO(), key) |
| 136 | if err != nil { |
| 137 | return fmt.Errorf("%s: create user %s: %w", a.modName, key, err) |
| 138 | } |
| 139 | if ok { |
| 140 | return fmt.Errorf("%s: credentials for %s already exist", a.modName, key) |
| 141 | } |
| 142 | |
| 143 | hash, err := HashCompute[hashAlgo](opts, password) |
| 144 | if err != nil { |
| 145 | return fmt.Errorf("%s: create user %s: hash generation: %w", a.modName, key, err) |
| 146 | } |
| 147 | |
| 148 | if err := tbl.SetKey(key, hashAlgo+":"+hash); err != nil { |
| 149 | return fmt.Errorf("%s: create user %s: %w", a.modName, key, err) |
| 150 | } |
| 151 | return nil |
| 152 | } |
| 153 | |
| 154 | func (a *Auth) SetUserPassword(username, password string) error { |
| 155 | tbl, ok := a.table.(module.MutableTable) |
no test coverage detected