Created
April 14, 2017 19:09
-
-
Save onidev/0f0da10e68611b972635a6270c5c5a0b to your computer and use it in GitHub Desktop.
Master Password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CLI for http://masterpasswordapp.com/algorithm.html | |
// C core lib used: https://github.com/Lyndir/MasterPassword/ | |
#include <iostream> | |
#include <cmath> | |
extern "C" { | |
#include "core/mpw-algorithm.h" | |
#undef enum | |
} | |
#ifdef WIN32 | |
#include <windows.h> | |
#else | |
#include <termios.h> | |
#include <unistd.h> | |
#endif | |
void SetStdinEcho(bool enable = true) | |
{ | |
#ifdef WIN32 | |
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); | |
DWORD mode; | |
GetConsoleMode(hStdin, &mode); | |
if( !enable ) | |
mode &= ~ENABLE_ECHO_INPUT; | |
else | |
mode |= ENABLE_ECHO_INPUT; | |
SetConsoleMode(hStdin, mode ); | |
#else | |
struct termios tty; | |
tcgetattr(STDIN_FILENO, &tty); | |
if( !enable ) | |
tty.c_lflag &= ~ECHO; | |
else | |
tty.c_lflag |= ECHO; | |
(void) tcsetattr(STDIN_FILENO, TCSANOW, &tty); | |
#endif | |
} | |
int main() | |
{ | |
std::string site; | |
std::string pass; | |
std::cout << "Url: "; | |
std::cin >> site; | |
std::cout << "Password: "; | |
SetStdinEcho(false); | |
std::cin >> pass; | |
SetStdinEcho(true); | |
const uint8_t* master = mpw_masterKeyForUser("Boris Marmontel", pass.c_str(), MPAlgorithmVersion3); | |
std::string generated_pass( mpw_passwordForSite(master, site.c_str(), MPSiteTypeGeneratedLong, 0, MPSiteVariantPassword, "", MPAlgorithmVersion3) ); | |
std::cout << generated_pass << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment