Skip to content

Commit

Permalink
Added new method getPassword to recursively prompt the user for their…
Browse files Browse the repository at this point in the history
… passwords if the entered passwords do not match.
  • Loading branch information
zbb93 committed Mar 11, 2017
1 parent a81d32e commit 345da74
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cryptogo.go
Expand Up @@ -61,19 +61,24 @@ func encryptHandle() {
panic("File not found")
}

password := getPassword()

fmt.Println("\nEncrypting...")
filecrypt.Encrypt(file, password)
fmt.Println("\nFile successfully protected")

}

func getPassword() []byte {
fmt.Print("Enter password: ")
password, _ := terminal.ReadPassword(0)
fmt.Print("\nConfirm password: ")
password2, _ := terminal.ReadPassword(0)

if !validatePassword(password, password2) {
panic("Passwords do not match")
fmt.Print("\nPasswords do not match. Please try again.\n")
return getPassword()
}

fmt.Println("\nEncrypting...")
filecrypt.Encrypt(file, password)
fmt.Println("\nFile successfully protected")

return password
}

func decryptHandle() {
Expand Down

0 comments on commit 345da74

Please sign in to comment.