forked from Pallinder/go-randomdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullprofile.go
139 lines (122 loc) · 3.53 KB
/
fullprofile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package randomdata
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"strconv"
"strings"
)
var letterRunes = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
var portraitDirs = []string{"men", "women"}
type Profile struct {
Gender string `json:"gender"`
Name struct {
First string `json:"first"`
Last string `json:"last"`
Title string `json:"title"`
} `json:"name"`
Location struct {
Street string `json:"street"`
City string `json:"city"`
State string `json:"state"`
Postcode int `json:"postcode"`
} `json:"location"`
Email string `json:"email"`
Login struct {
Username string `json:"username"`
Password string `json:"password"`
Salt string `json:"salt"`
Md5 string `json:"md5"`
Sha1 string `json:"sha1"`
Sha256 string `json:"sha256"`
} `json:"login"`
Dob string `json:"dob"`
Registered string `json:"registered"`
Phone string `json:"phone"`
Cell string `json:"cell"`
ID struct {
Name string `json:"name"`
Value interface{} `json:"value"`
} `json:"id"`
Picture struct {
Large string `json:"large"`
Medium string `json:"medium"`
Thumbnail string `json:"thumbnail"`
} `json:"picture"`
Nat string `json:"nat"`
}
func RandStringRunes(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[privateRand.Intn(len(letterRunes))]
}
return string(b)
}
func getMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
func getSha1(text string) string {
hasher := sha1.New()
hasher.Write([]byte(text))
sha := base64.URLEncoding.EncodeToString(hasher.Sum(nil))
return sha
}
func getSha256(text string) string {
hasher := sha256.New()
hasher.Write([]byte(text))
sha := base64.URLEncoding.EncodeToString(hasher.Sum(nil))
return sha
}
func GenerateProfile(gender int) *Profile {
profile := &Profile{}
if gender == Male {
profile.Gender = "male"
} else if gender == Female {
profile.Gender = "female"
} else {
gender = privateRand.Intn(2)
if gender == Male {
profile.Gender = "male"
} else {
profile.Gender = "female"
}
}
profile.Name.Title = Title(gender)
profile.Name.First = FirstName(gender)
profile.Name.Last = LastName()
profile.ID.Name = "SSN"
profile.ID.Value = fmt.Sprintf("%d-%d-%d",
Number(101, 999),
Number(01, 99),
Number(100, 9999),
)
profile.Email = strings.ToLower(profile.Name.First) + "." + strings.ToLower(profile.Name.Last) + "@example.com"
profile.Cell = PhoneNumber()
profile.Phone = PhoneNumber()
profile.Dob = FullDate()
profile.Registered = FullDate()
profile.Nat = "US"
profile.Location.City = City()
i, _ := strconv.Atoi(PostalCode("US"))
profile.Location.Postcode = i
profile.Location.State = State(2)
profile.Location.Street = StringNumber(1, "") + " " + Street()
profile.Login.Username = SillyName()
pass := SillyName()
salt := RandStringRunes(16)
profile.Login.Password = pass
profile.Login.Salt = salt
profile.Login.Md5 = getMD5Hash(pass + salt)
profile.Login.Sha1 = getSha1(pass + salt)
profile.Login.Sha256 = getSha256(pass + salt)
pic := privateRand.Intn(35)
profile.Picture.Large = fmt.Sprintf("https://randomuser.me/api/portraits/%s/%d.jpg", portraitDirs[gender], pic)
profile.Picture.Medium = fmt.Sprintf("https://randomuser.me/api/portraits/med/%s/%d.jpg", portraitDirs[gender], pic)
profile.Picture.Thumbnail = fmt.Sprintf("https://randomuser.me/api/portraits/thumb/%s/%d.jpg", portraitDirs[gender], pic)
return profile
}