This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34237] New: Weird error with getpass and crypt
- From: "jlarsen at fsu dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Nov 2007 14:37:36 -0000
- Subject: [Bug c++/34237] New: Weird error with getpass and crypt
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
compile with g++ -lcrypt
#include <iostream>
#include <string>
#include <utility>
#include <pwd.h>
using namespace std;
int main()
{
string username;
char salt[] = "$1$########";
char * passwordold = new char [100];
char * passwordnew = new char [100];
cout << "Enter username : ";
cin >> username;
passwordold = getpass("Enter password : ");
passwordnew = getpass("Enter new password: ");
string *strold = new string(crypt(passwordold,salt));
*strold = strold->substr(12,22);
string *strnew = new string(crypt(passwordnew,salt));
*strnew = strnew->substr(12,22);
cout << "cryptold: " << *strold << endl;
cout << "cryptnew: " << *strnew << endl;
return 1;
}
for input of passwords blah and blah2 it outputs
cryptold: oj.L0Tu9xXqtV9lyKLmdv0
cryptnew: oj.L0Tu9xXqtV9lyKLmdv0
which is the encrpytion of blah2 whatever I put into both the second one is
encryped. If I change it to cin >> instead of getpass it works.
if out cout << passwordold << passwordnew it still knows the correct passwords
entered.
The only fix I can find is reordering putting the request for the new
password after its calculated the old crypt, but that doesn't solve the fact
that somethign very wrong is going on here.
--
Summary: Weird error with getpass and crypt
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jlarsen at fsu dot edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34237