mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01: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:
31
Utils.cpp
31
Utils.cpp
@@ -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("");
|
||||
|
||||
1
Utils.h
1
Utils.h
@@ -35,6 +35,7 @@ public:
|
||||
static void PrintPrompt(const string& sMessage);
|
||||
static void PrintAction(const string& sMessage);
|
||||
static void PrintStatus(bool bSuccess, const string& sMessage = "");
|
||||
static string GetHashPass();
|
||||
static char* GetPass(const string& sPrompt);
|
||||
static bool GetInput(const string& sPrompt, string& sRet, const string& sDefault = "");
|
||||
static bool GetBoolInput(const string& sPrompt, bool bDefault);
|
||||
|
||||
Reference in New Issue
Block a user