if(decryptPwd(mypwd.c_str())==newmypwd) // just add .c_str() to mypwd
should work, as long as newmypwd is a string, as string can be compared against a
char* (not a char)
From: relational operators (string)
http://www.cplusplus.com/reference/string/string/operators/
1 2 3
|
bool operator== (const string& lhs, const string& rhs);
bool operator== (const char* lhs, const string& rhs);
bool operator== (const string& lhs, const char* rhs);
|
(these are non-member functions)
You could also use string::compare(), which behaves like strcmp().
if (0 == newmypwd.compare(decryptPwd(mypwd.c_str())))
But given the signature of decryptPwd
char* decryptPwd(char hash[64]);
it might just work if you change the signature to
string decryptPwd(const string& hash);
(as kbw has mentioned) as string provides operator[]. This assumes that decryptPwd uses [] internally, as suggested by the parameter).
Edit: After additional thought, the hash length of 64 makes me think this is actually going to be a binary hash. So you won't be able to handle it using std::string (it's just a "coincidence" that bytes and chars are the same thing in C++). But you could use a std::vector<char> or, in the C++11 case, a std::array<char, 64>. So the preferred signature for decryptPwd is probably:
std::string decryptPwd(const std::array<char, 64>& hash) // C++11
or
std::string decryptPwd(const std::vector<char>& hash) // C++03
As all of std::string, std::array, and std::vector provide operator[], decryptPwd might still work if you change the signature to use a standard container types rather than a C array.
Andy
PS From a security perspective, it might be better to use encryptPwd (assuming you have both decryptPwd and encryptPwd?) rather than decryptPwd to check passwords. That way you avoid having plain text passwords in memory. So you get the new password, you encrypt it, and compare it against the existing, encrypted one.