AskUserPassword prompts the user to enter the password for the given user ID.
(userid string, pwdType string, times int)
| 1142 | |
| 1143 | // AskUserPassword prompts the user to enter the password for the given user ID. |
| 1144 | func AskUserPassword(userid string, pwdType string, times int) (string, error) { |
| 1145 | AssertTrue(times == 1 || times == 2) |
| 1146 | AssertTrue(pwdType == "Current" || pwdType == "New") |
| 1147 | // ask for the user's password |
| 1148 | fmt.Printf("%s password for %v:", pwdType, userid) |
| 1149 | pd, err := term.ReadPassword(int(os.Stdin.Fd())) |
| 1150 | if err != nil { |
| 1151 | return "", errors.Wrapf(err, "while reading password") |
| 1152 | } |
| 1153 | fmt.Println() |
| 1154 | password := string(pd) |
| 1155 | |
| 1156 | if times == 2 { |
| 1157 | fmt.Printf("Retype %s password for %v:", strings.ToLower(pwdType), userid) |
| 1158 | pd2, err := term.ReadPassword(int(os.Stdin.Fd())) |
| 1159 | if err != nil { |
| 1160 | return "", errors.Wrapf(err, "while reading password") |
| 1161 | } |
| 1162 | fmt.Println() |
| 1163 | |
| 1164 | password2 := string(pd2) |
| 1165 | if password2 != password { |
| 1166 | return "", errors.Errorf("the two typed passwords do not match") |
| 1167 | } |
| 1168 | } |
| 1169 | return password, nil |
| 1170 | } |
| 1171 | |
| 1172 | // GetPassAndLogin uses the given credentials and client to perform the login operation. |
| 1173 | func GetPassAndLogin(dg *dgo.Dgraph, opt *CredOpt) error { |
no test coverage detected