Skip to content

Commit

Permalink
some requested changes.
Browse files Browse the repository at this point in the history
Signed-off-by: aryan <aryan1bhokare@gmail.com>
  • Loading branch information
aryan-bhokare committed May 23, 2024
1 parent 19d594f commit 3d2c6c1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions chaoscenter/authentication/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ const docTemplate = `{
},
"message": {
"type": "string",
"example": "Please ensure the password is 8 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"
"example": "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"
}
}
},
Expand All @@ -1233,7 +1233,7 @@ const docTemplate = `{
},
"message": {
"type": "string",
"example": "The username be atleast 3 characters long and atmost 12 characters long."
"example": "The username should be atleast 3 characters long and atmost 16 characters long."
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions chaoscenter/authentication/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@
},
"message": {
"type": "string",
"example": "Please ensure the password is 8 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"
"example": "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"
}
}
},
Expand All @@ -1223,7 +1223,7 @@
},
"message": {
"type": "string",
"example": "The username be atleast 3 characters long and atmost 12 characters long."
"example": "The username should be atleast 3 characters long and atmost 16 characters long."
}
}
},
Expand Down
7 changes: 4 additions & 3 deletions chaoscenter/authentication/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ definitions:
example: 401
type: integer
message:
example: Please ensure the password is 8 characters long and has 1 digit,
1 lowercase alphabet, 1 uppercase alphabet and 1 special character
example: Please ensure the password is atleast 8 characters long and atmost
16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet
and 1 special character
type: string
type: object
response.ErrStrictUsernamePolicyViolation:
Expand All @@ -92,7 +93,7 @@ definitions:
example: 401
type: integer
message:
example: The username be atleast 3 characters long and atmost 12 characters
example: The username should be atleast 3 characters long and atmost 16 characters
long.
type: string
type: object
Expand Down
4 changes: 2 additions & 2 deletions chaoscenter/authentication/api/handlers/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ type ErrUserDeactivated struct {

type ErrStrictPasswordPolicyViolation struct {
Code int `json:"code" example:"401"`
Message string `json:"message" example:"Please ensure the password is 8 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"`
Message string `json:"message" example:"Please ensure the password is atleast 8 characters long and atmost 16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"`
}

type ErrStrictUsernamePolicyViolation struct {
Code int `json:"code" example:"401"`
Message string `json:"message" example:"The username be atleast 3 characters long and atmost 12 characters long."`
Message string `json:"message" example:"The username should be atleast 3 characters long and atmost 16 characters long."`
}

type ErrEmptyProjectName struct {
Expand Down
4 changes: 2 additions & 2 deletions chaoscenter/authentication/pkg/utils/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ var ErrorDescriptions = map[AppError]string{
ErrInvalidRequest: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed",
ErrUnauthorized: "The user does not have requested authorization to access this resource",
ErrUserExists: "This username is already assigned to another user",
ErrStrictPasswordPolicyViolation: "Please ensure the password is 8 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character",
ErrStrictUsernamePolicyViolation: "The username be atleast 3 characters long and atmost 12 characters long.",
ErrStrictPasswordPolicyViolation: "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character",
ErrStrictUsernamePolicyViolation: "The username should be atleast 3 characters long and atmost 16 characters long.",
ErrEmptyProjectName: "Project name can't be empty",
ErrInvalidRole: "Role is invalid",
ErrProjectNotFound: "This project does not exist",
Expand Down
25 changes: 13 additions & 12 deletions chaoscenter/authentication/pkg/utils/sanitizers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func SanitizeString(input string) string {

/*
ValidateStrictPassword represents and checks for the following patterns:
- Input is at least 8 characters long
- Input contains at least one special character
- Input is at least 8 characters long and atmost 16 characters long
- Input contains at least one special character of these @$!%*?_&
- Input contains at least one digit
- Input contains at least one uppercase alphabet
- Input contains at least one lowercase alphabet
Expand All @@ -23,10 +23,15 @@ func ValidateStrictPassword(input string) error {
if len(input) < 8 {
return fmt.Errorf("password is less than 8 characters")
}

if len(input) > 16 {
return fmt.Errorf("password is more than 16 characters")
}

digits := `[0-9]{1}`
lowerAlphabets := `[a-z]{1}`
capitalAlphabets := `[A-Z]{1}`
specialCharacters := `[!@#~$%^&*()+|_]{1}`
specialCharacters := `[@$!%*?_&]{1}`
if b, err := regexp.MatchString(digits, input); !b || err != nil {
return fmt.Errorf("password does not contain digits")
}
Expand All @@ -42,17 +47,13 @@ func ValidateStrictPassword(input string) error {
return nil
}

func ValidateStrictUsername(username string) error {
if len(username) < 3 {
return fmt.Errorf("username must be at least three characters long")
}

if len(username) > 16 {
return fmt.Errorf("username must be at most sixteen characters long")
}
// Username must start with a letter - ^[a-zA-Z]
// Allow letters, digits, underscores, and hyphens - [a-zA-Z0-9_-]
// Ensure the length of the username is between 3 and 16 characters (1 character is already matched above) - {2,15}$

func ValidateStrictUsername(username string) error {
// Ensure username doesn't contain special characters (only letters, numbers, and underscores are allowed)
if matched, _ := regexp.MatchString(`^[a-zA-Z0-9_]+$`, username); !matched {
if matched, _ := regexp.MatchString(`^[a-zA-Z][a-zA-Z0-9_-]{2,15}$`, username); !matched {
return fmt.Errorf("username can only contain letters, numbers, and underscores")
}

Expand Down

0 comments on commit 3d2c6c1

Please sign in to comment.