-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnfpasswd.cpp
36 lines (27 loc) · 835 Bytes
/
nfpasswd.cpp
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
#include <termios.h>
#include <unistd.h>
#include <iostream>
#include "passwords.h"
std::string readPassword(const char* prompt) {
std::cout << prompt;
struct termios ttyNew, ttyOld;
tcgetattr(STDIN_FILENO, &ttyOld);
ttyNew = ttyOld;
ttyNew.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &ttyNew);
std::string password;
std::getline(std::cin, password);
tcsetattr(STDIN_FILENO, TCSAFLUSH, &ttyOld);
std::cout << std::endl;
return password;
}
int main() {
auto password = readPassword("Enter password: ");
auto passwordCheck = readPassword("Re-enter password: ");
if (password != passwordCheck) {
std::cout << "Passwords do not match!" << std::endl;
exit(1);
}
std::cout << Password::generatePassword(password) << std::endl;
return 0;
}