Skip to content

Commit

Permalink
Remove special characters from password generation
Browse files Browse the repository at this point in the history
  • Loading branch information
UnAfraid committed Sep 15, 2023
1 parent a820c1b commit 2680a5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions pkg/user/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,15 @@ const (
)

var (
lowerCharSet = "abcdedfghijklmnopqrst"
upperCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
specialCharSet = "!@#$%&*"
numberSet = "0123456789"
allCharSet = lowerCharSet + upperCharSet + specialCharSet + numberSet
lowerCharSet = "abcdedfghijklmnopqrst"
upperCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numberSet = "0123456789"
allCharSet = lowerCharSet + upperCharSet + numberSet
)

func generateRandomPassword(passwordLength, minSpecialChar, minNum, minUpperCase int) string {
func generateRandomPassword(passwordLength, minNum, minUpperCase int) string {
var pb strings.Builder

// Set special character
for i := 0; i < minSpecialChar; i++ {
random := rand.Intn(len(specialCharSet))
pb.WriteString(string(specialCharSet[random]))
}

// Set numeric
for i := 0; i < minNum; i++ {
random := rand.Intn(len(numberSet))
Expand All @@ -41,7 +34,7 @@ func generateRandomPassword(passwordLength, minSpecialChar, minNum, minUpperCase
pb.WriteString(string(upperCharSet[random]))
}

remainingLength := passwordLength - minSpecialChar - minNum - minUpperCase
remainingLength := passwordLength - minNum - minUpperCase
for i := 0; i < remainingLength; i++ {
random := rand.Intn(len(allCharSet))
pb.WriteString(string(allCharSet[random]))
Expand Down
2 changes: 1 addition & 1 deletion pkg/user/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (s *service) initializeInitialUser(ctx context.Context, email string, passw
email = "[email protected]"
}
if password == "" || password == "random" {
password = generateRandomPassword(16, 0, 4, 4)
password = generateRandomPassword(32, 4, 4)
generatedRandomPassword = true
}
createdUser, err := s.CreateUser(ctx, &CreateOptions{
Expand Down

0 comments on commit 2680a5f

Please sign in to comment.