mirror of
https://github.com/Luzifer/password.git
synced 2024-12-20 04:41:17 +00:00
Fix: Ensured minimal length of passwords
This is to prevent a endless loop when generating passwords with 1 or 2 characters. As they are not able to meet the minimal requirements they will get rejected by the security check and the generator will loop forever consuming 100% CPU at each process.
This commit is contained in:
parent
5e3037f751
commit
c034fcf285
1 changed files with 7 additions and 2 deletions
9
main.go
9
main.go
|
@ -65,6 +65,11 @@ func startAPIServer(c *cli.Context) {
|
|||
}
|
||||
|
||||
func printPassword(c *cli.Context) {
|
||||
if c.Int("length") < 5 {
|
||||
fmt.Println("Passwords with fewer than 5 characters are too insecure.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println(pwd.GeneratePassword(c.Int("length"), c.Bool("special")))
|
||||
}
|
||||
|
||||
|
@ -75,8 +80,8 @@ func handleAPIGetPasswordv1(res http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
special := r.URL.Query().Get("special") == "true"
|
||||
|
||||
if length > 128 {
|
||||
http.Error(res, "Please do not use length with more than 128 characters!", http.StatusNotAcceptable)
|
||||
if length > 128 || length < 5 {
|
||||
http.Error(res, "Please do not use length with more than 128 or fewer than 5 characters!", http.StatusNotAcceptable)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue