MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / read_password

Function read_password

libcppcryptfs/util/util.cpp:388–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386}
387
388bool read_password(WCHAR *pwbuf, int pwbuflen, const WCHAR *prompt)
389{
390 HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
391
392 if (!hStdin)
393 return false;
394
395 wcerr << (prompt ? prompt : L"Password: ");
396
397 DWORD old_mode = 0;
398 if (!GetConsoleMode(hStdin, &old_mode))
399 return false;
400
401 if (!SetConsoleMode(hStdin, old_mode & (~ENABLE_ECHO_INPUT)))
402 return false;
403
404 DWORD nRead = 0;
405
406 ReadConsole(hStdin, pwbuf, pwbuflen - 1, &nRead, NULL);
407
408 if (nRead >= 2 && pwbuf[nRead - 2] == L'\r' && pwbuf[nRead - 1] == L'\n')
409 pwbuf[nRead - 2] = '\0';
410
411 SetConsoleMode(hStdin, old_mode);
412
413 wcerr << L"\n";
414
415 return true;
416}
417
418
419bool

Callers 1

get_passwordFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected