Skip to content

Commit 4173088

Browse files
committed
update password validation rules based on jgknight feedback
1 parent a5f9920 commit 4173088

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

state/user.go

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,31 @@ var (
6868

6969
// ValidateAIMHandle returns an error if the instance is not a valid AIM screen name.
7070
// Possible errors:
71-
// - ErrAIMHandleLength: if the screen name is not between 3 and 16
72-
// characters
71+
// - ErrAIMHandleLength: if the screen name has less than 3 non-space
72+
// characters or more than 16 characters (including spaces).
7373
// - ErrAIMHandleInvalidFormat: if the screen name does not start with a
7474
// letter, ends with a space, or contains invalid characters
7575
func (s DisplayScreenName) ValidateAIMHandle() error {
76-
if len(s) < 3 || len(s) > 16 {
76+
if len(s) > 16 {
7777
return ErrAIMHandleLength
7878
}
7979

80-
// Must start with a letter, cannot end with a space,
81-
// and must contain only letters, numbers, and spaces
80+
// Must contain at least 3 letters.
81+
c := 0
82+
for _, r := range s {
83+
if unicode.IsLetter(r) {
84+
c++
85+
}
86+
if c == 3 {
87+
break
88+
}
89+
}
90+
if c < 3 {
91+
return ErrAIMHandleLength
92+
}
93+
94+
// Must start with a letter, cannot end with a space, and must contain only
95+
// letters, numbers, and spaces.
8296
if !unicode.IsLetter(rune(s[0])) || s[len(s)-1] == ' ' {
8397
return ErrAIMHandleInvalidFormat
8498
}
@@ -173,9 +187,8 @@ func (u *User) HashPassword(passwd string) error {
173187
}
174188

175189
// validateAIMPassword returns an error if the AIM password is invalid.
176-
// A valid password is 4-16 characters long. The minimum password length is
177-
// set here for software preservation purposes; operators should set more
178-
// stringent password requirements.
190+
// A valid password is 4-16 characters long. The min and max password length
191+
// values reflect AOL's password validation rules circa 2000.
179192
func validateAIMPassword(pass string) error {
180193
if len(pass) < 4 || len(pass) > 16 {
181194
return errors.New("password length must be between 4-16 characters")
@@ -184,12 +197,12 @@ func validateAIMPassword(pass string) error {
184197
}
185198

186199
// validateICQPassword returns an error if the ICQ password is invalid.
187-
// A valid password is 1-8 characters long. The minimum password length is set
188-
// here for software preservation purposes; operators should set more stringent
189-
// password requirements.
200+
// A valid password is 6-8 characters long. It's unclear what min length the
201+
// ICQ service required, so a plausible minimum value is set. The max length
202+
// reflects the password limitation imposed by old ICQ clients.
190203
func validateICQPassword(pass string) error {
191-
if len(pass) < 1 || len(pass) > 8 {
192-
return errors.New("password must be between 1 and 8 characters")
204+
if len(pass) < 6 || len(pass) > 8 {
205+
return errors.New("password must be between 6 and 8 characters")
193206
}
194207
return nil
195208
}

state/user_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ func TestDisplayScreenName_ValidateAIMHandle(t *testing.T) {
7373
input DisplayScreenName
7474
wantErr error
7575
}{
76-
{"Valid handle", "User123", nil},
76+
{"Valid handle no spaces", "User123", nil},
77+
{"Valid handle with min character count and space", "U SR", nil},
78+
{"Valid handle with max character count", "JustTheRightSize", nil},
79+
{"Valid handle with max character count and spaces", "Just RightSize", nil},
7780
{"Too short", "Us", ErrAIMHandleLength},
81+
{"Too short due to spaces", "U S", ErrAIMHandleLength},
7882
{"Too long", "ThisIsAReallyLongScreenName", ErrAIMHandleLength},
7983
{"Starts with number", "1User", ErrAIMHandleInvalidFormat},
8084
{"Ends with space", "User123 ", ErrAIMHandleInvalidFormat},

0 commit comments

Comments
 (0)