Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvoe committed Jan 16, 2024
2 parents 7cc1c97 + d59376d commit bb325f6
Show file tree
Hide file tree
Showing 43 changed files with 362 additions and 259 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ Svg(options *SVGOptions) string

```go
Date() time.Time
PastDate() time.Time
FutureDate() time.Time
DateRange(start, end time.Time) time.Time
NanoSecond() int
Expand Down
32 changes: 16 additions & 16 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func addAddressLookup() {
AddFuncLookup("address", Info{
Display: "Address",
Category: "address",
Description: "Random set of address info",
Description: "Residential location including street, city, state, country and postal code",
Example: `{
"address": "364 Unionsville, Norfolk, Ohio 99536",
"street": "364 Unionsville",
Expand All @@ -219,7 +219,7 @@ func addAddressLookup() {
AddFuncLookup("city", Info{
Display: "City",
Category: "address",
Description: "Random city",
Description: "Part of a country with significant population, often a central hub for culture and commerce",
Example: "Marcelside",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -230,7 +230,7 @@ func addAddressLookup() {
AddFuncLookup("country", Info{
Display: "Country",
Category: "address",
Description: "Random country",
Description: "Nation with its own government and defined territory",
Example: "United States of America",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -241,7 +241,7 @@ func addAddressLookup() {
AddFuncLookup("countryabr", Info{
Display: "Country Abbreviation",
Category: "address",
Description: "Random 2 digit country abbreviation",
Description: "Shortened 2-letter form of a country's name",
Example: "US",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -252,7 +252,7 @@ func addAddressLookup() {
AddFuncLookup("state", Info{
Display: "State",
Category: "address",
Description: "Random state",
Description: "Governmental division within a country, often having its own laws and government",
Example: "Illinois",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -263,7 +263,7 @@ func addAddressLookup() {
AddFuncLookup("stateabr", Info{
Display: "State Abbreviation",
Category: "address",
Description: "Random 2 digit state abbreviation",
Description: "Shortened 2-letter form of a country's state",
Example: "IL",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -274,7 +274,7 @@ func addAddressLookup() {
AddFuncLookup("street", Info{
Display: "Street",
Category: "address",
Description: "Random full street",
Description: "Public road in a city or town, typically with houses and buildings on each side",
Example: "364 East Rapidsborough",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -285,7 +285,7 @@ func addAddressLookup() {
AddFuncLookup("streetname", Info{
Display: "Street Name",
Category: "address",
Description: "Random street name",
Description: "Name given to a specific road or street",
Example: "View",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -296,7 +296,7 @@ func addAddressLookup() {
AddFuncLookup("streetnumber", Info{
Display: "Street Number",
Category: "address",
Description: "Random street number",
Description: "Numerical identifier assigned to a street",
Example: "13645",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -307,7 +307,7 @@ func addAddressLookup() {
AddFuncLookup("streetprefix", Info{
Display: "Street Prefix",
Category: "address",
Description: "Random street prefix",
Description: "Directional or descriptive term preceding a street name, like 'East' or 'Main'",
Example: "Lake",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -318,7 +318,7 @@ func addAddressLookup() {
AddFuncLookup("streetsuffix", Info{
Display: "Street Suffix",
Category: "address",
Description: "Random street suffix",
Description: "Designation at the end of a street name indicating type, like 'Avenue' or 'Street'",
Example: "land",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -329,7 +329,7 @@ func addAddressLookup() {
AddFuncLookup("zip", Info{
Display: "Zip",
Category: "address",
Description: "Random street zip",
Description: "Numerical code for postal address sorting, specific to a geographic area",
Example: "13645",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -340,7 +340,7 @@ func addAddressLookup() {
AddFuncLookup("latitude", Info{
Display: "Latitude",
Category: "address",
Description: "Random latitude",
Description: "Geographic coordinate specifying north-south position on Earth's surface",
Example: "-73.534056",
Output: "float",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -351,7 +351,7 @@ func addAddressLookup() {
AddFuncLookup("latituderange", Info{
Display: "Latitude Range",
Category: "address",
Description: "Random latitude between given range",
Description: "Latitude number between the given range (default min=0, max=90)",
Example: "22.921026",
Output: "float",
Params: []Param{
Expand Down Expand Up @@ -381,7 +381,7 @@ func addAddressLookup() {
AddFuncLookup("longitude", Info{
Display: "Longitude",
Category: "address",
Description: "Random longitude",
Description: "Geographic coordinate indicating east-west position on Earth's surface",
Example: "-147.068112",
Output: "float",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -392,7 +392,7 @@ func addAddressLookup() {
AddFuncLookup("longituderange", Info{
Display: "Longitude Range",
Category: "address",
Description: "Random longitude between given range",
Description: "Longitude number between the given range (default min=0, max=180)",
Example: "-8.170450",
Output: "float",
Params: []Param{
Expand Down
14 changes: 7 additions & 7 deletions animal.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func addAnimalLookup() {
AddFuncLookup("petname", Info{
Display: "Pet Name",
Category: "animal",
Description: "Random pet name",
Description: "Affectionate nickname given to a pet",
Example: "Ozzy Pawsborne",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -115,7 +115,7 @@ func addAnimalLookup() {
AddFuncLookup("animal", Info{
Display: "Animal",
Category: "animal",
Description: "Random animal",
Description: "Living creature with the ability to move, eat, and interact with its environment",
Example: "elk",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -126,7 +126,7 @@ func addAnimalLookup() {
AddFuncLookup("animaltype", Info{
Display: "Animal Type",
Category: "animal",
Description: "Random animal type",
Description: "Type of animal, such as mammals, birds, reptiles, etc.",
Example: "amphibians",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -137,7 +137,7 @@ func addAnimalLookup() {
AddFuncLookup("farmanimal", Info{
Display: "Farm Animal",
Category: "animal",
Description: "Random farm animal",
Description: "Animal name commonly found on a farm",
Example: "Chicken",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -148,7 +148,7 @@ func addAnimalLookup() {
AddFuncLookup("cat", Info{
Display: "Cat",
Category: "animal",
Description: "Random cat type",
Description: "Various breeds that define different cats",
Example: "Chausie",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -159,7 +159,7 @@ func addAnimalLookup() {
AddFuncLookup("dog", Info{
Display: "Dog",
Category: "animal",
Description: "Random dog type",
Description: "Various breeds that define different dogs",
Example: "Norwich Terrier",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -170,7 +170,7 @@ func addAnimalLookup() {
AddFuncLookup("bird", Info{
Display: "Bird",
Category: "animal",
Description: "Random bird type",
Description: "Distinct species of birds",
Example: "goose",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand Down
6 changes: 3 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func addAppLookup() {
AddFuncLookup("appname", Info{
Display: "App Name",
Category: "app",
Description: "Random app name",
Description: "Name for an application",
Example: "Parkrespond",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -76,7 +76,7 @@ func addAppLookup() {
AddFuncLookup("appversion", Info{
Display: "App Version",
Category: "app",
Description: "Random app version",
Description: "Version number for an app, following Semantic versioning format",
Example: "1.12.14",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand All @@ -87,7 +87,7 @@ func addAppLookup() {
AddFuncLookup("appauthor", Info{
Display: "App Author",
Category: "app",
Description: "Random app author",
Description: "Name for an app developer or authoring entity",
Example: "Qado Energy, Inc.",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
Expand Down
69 changes: 44 additions & 25 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,56 @@ func password(r *rand.Rand, lower bool, upper bool, numeric bool, special bool,
if num < 5 {
num = 5
}
i := 0
b := make([]byte, num)
var passString string

// Setup weights
items := make([]any, 0)
weights := make([]float32, 0)
if lower {
passString += lowerStr
b[i] = lowerStr[r.Int63()%int64(len(lowerStr))]
i++
items = append(items, "lower")
weights = append(weights, 4)
}
if upper {
passString += upperStr
b[i] = upperStr[r.Int63()%int64(len(upperStr))]
i++
items = append(items, "upper")
weights = append(weights, 4)
}
if numeric {
passString += numericStr
b[i] = numericStr[r.Int63()%int64(len(numericStr))]
i++
items = append(items, "numeric")
weights = append(weights, 3)
}
if special {
passString += specialStr
b[i] = specialStr[r.Int63()%int64(len(specialStr))]
i++
items = append(items, "special")
weights = append(weights, 2)
}
if space {
passString += spaceStr
b[i] = spaceStr[r.Int63()%int64(len(spaceStr))]
i++
items = append(items, "space")
weights = append(weights, 1)
}

// Set default if empty
if passString == "" {
passString = lowerStr + numericStr
// If no items are selected then default to lower, upper, numeric
if len(items) == 0 {
items = append(items, "lower", "upper", "numeric")
weights = append(weights, 4, 4, 3)
}

// Loop through and add it up
for i <= num-1 {
b[i] = passString[r.Int63()%int64(len(passString))]
i++
// Create byte slice
b := make([]byte, num)

for i := 0; i <= num-1; i++ {
// Run weighted
weight, _ := weighted(r, items, weights)

switch weight.(string) {
case "lower":
b[i] = lowerStr[r.Int63()%int64(len(lowerStr))]
case "upper":
b[i] = upperStr[r.Int63()%int64(len(upperStr))]
case "numeric":
b[i] = numericStr[r.Int63()%int64(len(numericStr))]
case "special":
b[i] = specialSafeStr[r.Int63()%int64(len(specialSafeStr))]
case "space":
b[i] = spaceStr[r.Int63()%int64(len(spaceStr))]
}
}

// Shuffle bytes
Expand All @@ -80,6 +91,14 @@ func password(r *rand.Rand, lower bool, upper bool, numeric bool, special bool,
b[i], b[j] = b[j], b[i]
}

// Replace first or last character if it's a space, and other options are available
if b[0] == ' ' {
b[0] = password(r, lower, upper, numeric, special, false, 1)[0]
}
if b[len(b)-1] == ' ' {
b[len(b)-1] = password(r, lower, upper, numeric, special, false, 1)[0]
}

return string(b)
}

Expand Down
22 changes: 15 additions & 7 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ func TestPassword(t *testing.T) {
if pass == "" {
t.Error("Password should not be empty")
}

// Test it doesnt start or end with a space
for i := 0; i < 1000; i++ {
pass = Password(true, true, true, true, true, length)
if pass[0] == ' ' || pass[len(pass)-1] == ' ' {
t.Error("Password should not start or end with a space")
}
}
}

func ExamplePassword() {
Expand All @@ -71,9 +79,9 @@ func ExamplePassword() {
// Output: vodnqxzsuptgehrzylximvylxzoywexw
// ZSRQWJFJWCSTVGXKYKWMLIAFGFELFJRG
// 61718615932495608398906260648432
// @$,@#:,(,).{?:%?)>*..<=};#$(:{==
// CkF{wwb:?Kb},w?vdz{Zox C&>Prt99:
// j ;9X
// !*&#$$??_!&!#.@@-!_!!$$-?_$&.@-&
// d6UzSwXvJ81 7QPvlse@l ln VmvU5jd
// UKTn2
}

func ExampleFaker_Password() {
Expand All @@ -88,15 +96,15 @@ func ExampleFaker_Password() {
// Output: vodnqxzsuptgehrzylximvylxzoywexw
// ZSRQWJFJWCSTVGXKYKWMLIAFGFELFJRG
// 61718615932495608398906260648432
// @$,@#:,(,).{?:%?)>*..<=};#$(:{==
// CkF{wwb:?Kb},w?vdz{Zox C&>Prt99:
// j ;9X
// !*&#$$??_!&!#.@@-!_!!$$-?_$&.@-&
// d6UzSwXvJ81 7QPvlse@l ln VmvU5jd
// UKTn2
}

func BenchmarkPassword(b *testing.B) {
b.Run("package", func(b *testing.B) {
for i := 0; i < b.N; i++ {
Password(true, true, true, true, true, 8)
Password(true, true, true, true, true, 50)
}
})

Expand Down
Loading

0 comments on commit bb325f6

Please sign in to comment.