Skip to content

Commit

Permalink
safe special - updated special safe characters with something recomme…
Browse files Browse the repository at this point in the history
…nded by 1Password
  • Loading branch information
brianvoe committed Jun 21, 2024
1 parent a539896 commit 356c601
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ func password(f *Faker, lower bool, upper bool, numeric bool, special bool, spac
items := make([]any, 0)
weights := make([]float32, 0)
if lower {
items = append(items, "lower")
items = append(items, "l")
weights = append(weights, 4)
}
if upper {
items = append(items, "upper")
items = append(items, "u")
weights = append(weights, 4)
}
if numeric {
items = append(items, "numeric")
items = append(items, "n")
weights = append(weights, 3)
}
if special {
items = append(items, "special")
items = append(items, "e")
weights = append(weights, 2)
}
if space {
items = append(items, "space")
items = append(items, "a")
weights = append(weights, 1)
}

// If no items are selected then default to lower, upper, numeric
if len(items) == 0 {
items = append(items, "lower", "upper", "numeric")
items = append(items, "l", "u", "n")
weights = append(weights, 4, 4, 3)
}

Expand All @@ -70,15 +70,15 @@ func password(f *Faker, lower bool, upper bool, numeric bool, special bool, spac
weight, _ := weighted(f, items, weights)

switch weight.(string) {
case "lower":
case "l":
b[i] = lowerStr[f.Int64()%int64(len(lowerStr))]
case "upper":
case "u":
b[i] = upperStr[f.Int64()%int64(len(upperStr))]
case "numeric":
case "n":
b[i] = numericStr[f.Int64()%int64(len(numericStr))]
case "special":
case "e":
b[i] = specialSafeStr[f.Int64()%int64(len(specialSafeStr))]
case "space":
case "a":
b[i] = spaceStr[f.Int64()%int64(len(spaceStr))]
}
}
Expand Down
8 changes: 4 additions & 4 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func ExamplePassword() {
// Output: cfelntbponnbbzrhswobuwlxajeeclrx
// KYEKNGUUNKUYSFBUFFTGDKUVCVYKPONP
// 43622637275953627791234759581343
// !?*-_-?#@!*?@?-&@!*!*?_!#$@@@**@
// .DTHJ&@oF#d.L5F65 N.-#U5xWX F0DI
// @.__-._-!-!_..!-_*_*__-@*.__.__!
// -DTHJ@.oF@d@L5F65 N-.@U5xWX F0DI
// foZnB
}

Expand All @@ -78,8 +78,8 @@ func ExampleFaker_Password() {
// Output: cfelntbponnbbzrhswobuwlxajeeclrx
// KYEKNGUUNKUYSFBUFFTGDKUVCVYKPONP
// 43622637275953627791234759581343
// !?*-_-?#@!*?@?-&@!*!*?_!#$@@@**@
// .DTHJ&@oF#d.L5F65 N.-#U5xWX F0DI
// @.__-._-!-!_..!-_*_*__-@*.__.__!
// -DTHJ@.oF@d@L5F65 N-.@U5xWX F0DI
// foZnB
}

Expand Down
2 changes: 1 addition & 1 deletion faker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Example() {
// Credit Card: 6282690620525711
// Hacker Phrase: Try to bundle the PNG firewall, maybe it will deconstruct the open-source bandwidth!
// Job Title: Assistant
// Password: Nyf8p8ka1Kvgn**@3H&$w7j01yM1vkc2
// Password: Nyf8p8ka1Kvgn...3H*.w7j01yM1vkc2
}

func ExampleNew() {
Expand Down
2 changes: 1 addition & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const lowerStr = "abcdefghijklmnopqrstuvwxyz"
const upperStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const numericStr = "0123456789"
const specialStr = "@#$%&?|!(){}<>=*+-_:;,."
const specialSafeStr = "@#$&?!-_*."
const specialSafeStr = "!@.-_*" // https://github.com/1Password/spg/pull/22
const spaceStr = " "
const allStr = lowerStr + upperStr + numericStr + specialStr + spaceStr
const vowels = "aeiou"
Expand Down

0 comments on commit 356c601

Please sign in to comment.