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

Method CreateUserHash

internal/auth/pass_table/table.go:120–152  ·  view source on GitHub ↗
(username, password string, hashAlgo string, opts HashOpts)

Source from the content-addressed store, hash-verified

118}
119
120func (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
154func (a *Auth) SetUserPassword(username, password string) error {
155 tbl, ok := a.table.(module.MutableTable)

Callers 2

CreateUserMethod · 0.95
usersCreateFunction · 0.80

Calls 2

LookupMethod · 0.65
SetKeyMethod · 0.65

Tested by

no test coverage detected