mirror of
https://github.com/znc/znc.git
synced 2026-08-06 08:52:57 +02:00
Added GetHashPass()
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@206 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "Utils.h"
|
||||
#include "md5.h"
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
@@ -218,6 +219,36 @@ int CUtils::MakeDir(const string& sPath, mode_t iMode) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
string CUtils::GetHashPass() {
|
||||
while (true) {
|
||||
char* pass = CUtils::GetPass("Enter Password");
|
||||
char* pass1 = (char*) malloc(strlen(pass) +1);
|
||||
strcpy(pass1, pass); // Make a copy of this since it is stored in a static buffer and will be overwritten when we fill pass2 below
|
||||
memset((char*) pass, 0, strlen(pass)); // null out our pass so it doesn't sit in memory
|
||||
char* pass2 = CUtils::GetPass("Confirm Password");
|
||||
int iLen = strlen(pass1);
|
||||
|
||||
if (strcmp(pass1, pass2) != 0) {
|
||||
CUtils::PrintError("The supplied passwords did not match");
|
||||
} else if (!iLen) {
|
||||
CUtils::PrintError("You can not use an empty password");
|
||||
} else {
|
||||
string sRet((const char*) CMD5(pass1, iLen));
|
||||
memset((char*) pass1, 0, iLen); // null out our pass so it doesn't sit in memory
|
||||
memset((char*) pass2, 0, strlen(pass2)); // null out our pass so it doesn't sit in memory
|
||||
free(pass1);
|
||||
|
||||
return sRet;
|
||||
}
|
||||
|
||||
memset((char*) pass1, 0, iLen); // null out our pass so it doesn't sit in memory
|
||||
memset((char*) pass2, 0, strlen(pass2)); // null out our pass so it doesn't sit in memory
|
||||
free(pass1);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
char* CUtils::GetPass(const string& sPrompt) {
|
||||
PrintPrompt(sPrompt);
|
||||
return getpass("");
|
||||
|
||||
Reference in New Issue
Block a user