forked from TrueCloudLab/rclone
Make Password parameters obey Optional flag and offer to generate random ones
This commit is contained in:
parent
b1de4c8cba
commit
9985fc40f4
1 changed files with 36 additions and 3 deletions
39
fs/config.go
39
fs/config.go
|
@ -554,7 +554,7 @@ func GetPassword(prompt string) string {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return password
|
return password
|
||||||
}
|
}
|
||||||
fmt.Printf("Bad password: %v", err)
|
fmt.Printf("Bad password: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,7 +829,7 @@ func OkRemote(name string) bool {
|
||||||
ConfigFile.DeleteSection(name)
|
ConfigFile.DeleteSection(name)
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
ErrorLog(nil, "Bad choice %d", i)
|
ErrorLog(nil, "Bad choice %c", i)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -854,7 +854,40 @@ func RemoteConfig(name string) {
|
||||||
func ChooseOption(o *Option) string {
|
func ChooseOption(o *Option) string {
|
||||||
fmt.Println(o.Help)
|
fmt.Println(o.Help)
|
||||||
if o.IsPassword {
|
if o.IsPassword {
|
||||||
return MustObscure(ChangePassword("the"))
|
actions := []string{"yYes type in my own password", "gGenerate random password"}
|
||||||
|
if o.Optional {
|
||||||
|
actions = append(actions, "nNo leave this optional password blank")
|
||||||
|
}
|
||||||
|
var password string
|
||||||
|
switch i := Command(actions); i {
|
||||||
|
case 'y':
|
||||||
|
password = ChangePassword("the")
|
||||||
|
case 'g':
|
||||||
|
for {
|
||||||
|
fmt.Printf("Password strength in bits.\n64 is just about memorable\n128 is secure\n1024 is the maximum\n")
|
||||||
|
bits := ChooseNumber("Bits", 64, 1024)
|
||||||
|
bytes := bits / 8
|
||||||
|
if bits%8 != 0 {
|
||||||
|
bytes++
|
||||||
|
}
|
||||||
|
var pw = make([]byte, bytes)
|
||||||
|
n, _ := rand.Read(pw)
|
||||||
|
if n != bytes {
|
||||||
|
log.Fatalf("password short read: %d", n)
|
||||||
|
}
|
||||||
|
password = base64.RawURLEncoding.EncodeToString(pw)
|
||||||
|
fmt.Printf("Your password is: %s\n", password)
|
||||||
|
fmt.Printf("Use this password?\n")
|
||||||
|
if Confirm() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'n':
|
||||||
|
return ""
|
||||||
|
default:
|
||||||
|
ErrorLog(nil, "Bad choice %c", i)
|
||||||
|
}
|
||||||
|
return MustObscure(password)
|
||||||
}
|
}
|
||||||
if len(o.Examples) > 0 {
|
if len(o.Examples) > 0 {
|
||||||
var values []string
|
var values []string
|
||||||
|
|
Loading…
Reference in a new issue