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

Function usersCreate

internal/cli/ctl/users.go:185–211  ·  view source on GitHub ↗
(be module.PlainUserDB, ctx *cli.Context)

Source from the content-addressed store, hash-verified

183}
184
185func usersCreate(be module.PlainUserDB, ctx *cli.Context) error {
186 username := ctx.Args().First()
187 if username == "" {
188 return cli.Exit("Error: USERNAME is required", 2)
189 }
190
191 var pass string
192 if ctx.IsSet("password") {
193 pass = ctx.String("password")
194 } else {
195 var err error
196 pass, err = clitools2.ReadPassword("Enter password for new user")
197 if err != nil {
198 return err
199 }
200 }
201
202 if beHash, ok := be.(*pass_table.Auth); ok {
203 return beHash.CreateUserHash(username, pass, ctx.String("hash"), pass_table.HashOpts{
204 BcryptCost: ctx.Int("bcrypt-cost"),
205 })
206 } else if ctx.IsSet("hash") || ctx.IsSet("bcrypt-cost") {
207 return cli.Exit("Error: --hash cannot be used with non-pass_table credentials DB", 2)
208 } else {
209 return be.CreateUser(username, pass)
210 }
211}
212
213func usersRemove(be module.PlainUserDB, ctx *cli.Context) error {
214 username := ctx.Args().First()

Callers 1

initFunction · 0.85

Calls 6

ArgsMethod · 0.80
IsSetMethod · 0.80
CreateUserHashMethod · 0.80
IntMethod · 0.80
CreateUserMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected