MCPcopy Index your code
hub / github.com/foxcpp/maddy / SetUserPassword

Method SetUserPassword

internal/auth/pass_table/table.go:154–177  ·  view source on GitHub ↗
(username, password string)

Source from the content-addressed store, hash-verified

152}
153
154func (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
179func (a *Auth) DeleteUser(username string) error {
180 tbl, ok := a.table.(module.MutableTable)

Callers

nothing calls this directly

Calls 1

SetKeyMethod · 0.65

Tested by

no test coverage detected