func newUser(conn *wrappedConnection) types.User { for { name := utils.GetUserInput(conn, "Desired username: "******"" { return nil } user := model.GetUserByName(name) password := "" if user != nil { utils.WriteLine(conn, "That name is unavailable", types.ColorModeNone) } else if err := utils.ValidateName(name); err != nil { utils.WriteLine(conn, err.Error(), types.ColorModeNone) } else { conn.WillEcho() for { pass1 := utils.GetRawUserInputSuffix(conn, "Desired password: "******"\r\n", types.ColorModeNone) if len(pass1) < 7 { utils.WriteLine(conn, "Passwords must be at least 7 letters in length", types.ColorModeNone) continue } pass2 := utils.GetRawUserInputSuffix(conn, "Confirm password: "******"\r\n", types.ColorModeNone) if pass1 != pass2 { utils.WriteLine(conn, "Passwords do not match", types.ColorModeNone) continue } password = pass1 break } conn.WontEcho() admin := model.UserCount() == 0 user = model.CreateUser(name, password, admin) return user } } }
func login(conn *wrappedConnection) types.User { for { username := utils.GetUserInput(conn, "Username: "******"" { return nil } user := model.GetUserByName(username) if user == nil { utils.WriteLine(conn, "User not found", types.ColorModeNone) } else if user.IsOnline() { utils.WriteLine(conn, "That user is already online", types.ColorModeNone) } else { attempts := 1 conn.WillEcho() for { password := utils.GetRawUserInputSuffix(conn, "Password: "******"\r\n", types.ColorModeNone) // TODO - Disabling password verification to make development easier if user.VerifyPassword(password) || true { break } if attempts >= 3 { utils.WriteLine(conn, "Too many failed login attempts", types.ColorModeNone) conn.Close() panic("Booted user due to too many failed logins (" + user.GetName() + ")") } attempts++ time.Sleep(2 * time.Second) utils.WriteLine(conn, "Invalid password", types.ColorModeNone) } conn.WontEcho() return user } } }
func (self *connectionHandler) GetInput(prompt string) string { return utils.GetUserInput(self.conn, prompt, types.ColorModeNone) }
func (self *User) GetInput(prompt string) string { return utils.GetUserInput(self.conn, prompt, self.GetColorMode()) }