11package user
22
33import (
4- crand "crypto/rand"
5- "encoding/binary"
64 "encoding/json"
75 "fmt"
8- "log"
9- "math/rand"
106 "reflect"
11- "strings"
127
8+ gopass "github.com/sethvargo/go-password/password"
139 "github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
1410
1511 "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal"
@@ -92,7 +88,7 @@ func (cmd *CreateCommand) Run(args []string) error {
9288
9389 password := cmd .Password
9490 if password == "generate" {
95- password = string ( GeneratePassword ( 23 , 4 ) )
91+ password = gopass . MustGenerate ( 18 , 4 , 4 , false , false )
9692 }
9793
9894 vpnPassword := cmd .VpnPassword
@@ -139,54 +135,9 @@ func printUser(user datatypes.User_Customer, password string, ui terminal.UI) {
139135 table .Print ()
140136}
141137
142- // random source leveraging crypto/rand to provide
143- // true non-determinstic
144- type cryptoSource struct {}
145-
146- func (s cryptoSource ) Seed (seed int64 ) {}
147-
148- func (s cryptoSource ) Int63 () int64 {
149- return int64 (s .Uint64 () & ^ uint64 (1 << 63 ))
150- }
151-
152- func (s cryptoSource ) Uint64 () (v uint64 ) {
153- err := binary .Read (crand .Reader , binary .BigEndian , & v )
154- if err != nil {
155- log .Fatal (err )
156- }
157- return v
158- }
159-
160- // GeneratePassword will create a random password
161- // Returns a 23 character random string
162- // 0 only number
163- // 1 lower and upper
164- // 2 upper
165- // 3 special
166- // 4 all
167- func GeneratePassword (size int , kind int ) []byte {
168- ikind , kinds , result := kind , [][]int {{10 , 48 }, {26 , 97 }, {26 , 65 }, {10 , 38 }}, make ([]byte , size )
169- isAll := kind > 3 || kind < 0
170-
171- // #nosec G404: Use "crypto/rand" as the seed, which should resolve the pseudo "math/rand"
172- rnd := rand .New (& cryptoSource {})
173- generate := true
174- for generate {
175- result = make ([]byte , size )
176- for i := 0 ; i < size ; i ++ {
177- if isAll { // random ikind
178- ikind = rnd .Intn (4 )
179- }
180- scope , base := kinds [ikind ][0 ], kinds [ikind ][1 ]
181- result [i ] = uint8 (base + rnd .Intn (scope ))
182- }
183- generate = ! IsValidPassword (string (result ))
184- }
185- return result
186- }
187-
138+ // Values of B get copied into A
139+ // A <--- B
188140func StructAssignment (A , B interface {}) { //a =b
189-
190141 av := reflect .ValueOf (A ).Elem ()
191142 at := av .Type ()
192143
@@ -202,34 +153,3 @@ func StructAssignment(A, B interface{}) { //a =b
202153 }
203154 }
204155}
205-
206- func IsValidPassword (output string ) bool {
207- output = strings .TrimSpace (output )
208- var uppercase , lowercase , number , simbol , lenght bool
209- //Verify lenght is 23
210- if len (output ) == 23 {
211- lenght = true
212- }
213- for _ , char := range output {
214- //Verify exist uppercase
215- if int (char ) >= 65 && int (char ) <= 90 {
216- uppercase = true
217- }
218- //Verify exist lowercase
219- if int (char ) >= 97 && int (char ) <= 122 {
220- lowercase = true
221- }
222- //Verify exist number
223- if int (char ) >= 48 && int (char ) <= 57 {
224- number = true
225- }
226- //Verify exist simbol
227- if int (char ) >= 33 && int (char ) <= 47 {
228- simbol = true
229- }
230- }
231- if uppercase && lowercase && number && simbol && lenght {
232- return true
233- }
234- return false
235- }
0 commit comments