| 152 | } |
| 153 | |
| 154 | func (a *Auth) SetUserPassword(username, password string) error { |
| 155 | tbl, ok := a.table.(module.MutableTable) |
| 156 | if !ok { |
| 157 | return fmt.Errorf("%s: table is not mutable, no management functionality available", a.modName) |
| 158 | } |
| 159 | |
| 160 | key, err := precis.UsernameCaseMapped.CompareKey(username) |
| 161 | if err != nil { |
| 162 | return fmt.Errorf("%s: set password %s (raw): %w", a.modName, username, err) |
| 163 | } |
| 164 | |
| 165 | // TODO: Allow to customize hash function. |
| 166 | hash, err := HashCompute[HashBcrypt](HashOpts{ |
| 167 | BcryptCost: bcrypt.DefaultCost, |
| 168 | }, password) |
| 169 | if err != nil { |
| 170 | return fmt.Errorf("%s: set password %s: hash generation: %w", a.modName, key, err) |
| 171 | } |
| 172 | |
| 173 | if err := tbl.SetKey(key, "bcrypt:"+hash); err != nil { |
| 174 | return fmt.Errorf("%s: set password %s: %w", a.modName, key, err) |
| 175 | } |
| 176 | return nil |
| 177 | } |
| 178 | |
| 179 | func (a *Auth) DeleteUser(username string) error { |
| 180 | tbl, ok := a.table.(module.MutableTable) |