diff --git a/gopassword.go b/gopassword.go index daa98e7..0763845 100644 --- a/gopassword.go +++ b/gopassword.go @@ -25,8 +25,8 @@ func Generate(n ...int) string { randString := base64.StdEncoding.EncodeToString(randBytes) password := randString[:length] - password = strings.Replace(password, "+", defaultSpecialChar, -1) - password = strings.Replace(password, "/", defaultSpecialChar, -1) + password = strings.ReplaceAll(password, "+", defaultSpecialChar) + password = strings.ReplaceAll(password, "/", defaultSpecialChar) return password } diff --git a/gopassword_test.go b/gopassword_test.go index 4a6ea51..bf3c257 100644 --- a/gopassword_test.go +++ b/gopassword_test.go @@ -24,7 +24,7 @@ func TestGenerate(t *testing.T) { }) t.Run("It must contain only alphanumeric or underscore characters", func(t *testing.T) { - allowedCharacters, _ := regexp.Compile("^[a-zA-Z0-9_]+$") + allowedCharacters := regexp.MustCompile("^[a-zA-Z0-9_]+$") // Try various times to ensure the result is not casual for _ = range 1000 {