/********************************************************************** * * getpw.cpp -- * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Copyright (C) 2000 The New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * **********************************************************************/ #define _XOPEN_SOURCE 1 /* following is for solaris */ #define _XOPEN_SOURCE_EXTENDED 1 #include "gsdlconf.h" // include crypt #if defined(__WIN32__) #include "crypt.h" #else #include "config.h" #if defined(HAVE_CRYPT_H) #include #endif #if defined(HAVE_UNISTD_H) #include #endif /* we are probably in trouble if we have neither crypt.h or unistd.h, but for now we'll do nothing about it... */ #endif /* not WIN32 */ #if defined(GSDL_USE_OBJECTSPACE) # include #elif defined(GSDL_USE_IOS_H) # include #else # include #endif // use the standard namespace #if !defined (GSDL_NAMESPACE_BROKEN) #if defined(GSDL_USE_OBJECTSPACE) using namespace ospace::std; #else using namespace std; #endif #endif #include //#include int main (int argc, char *argv[]) { int password_ok = 0; char c[129]; int i; for (i=0; i<3; i++) { #if defined(__WIN32__) cerr << "Enter password (will appear on screen): "; char a[129]; cin.getline(a, 128); #else char *a = getpass("Enter password:"); #endif int len = strlen (a); if (len < 3 || len > 128) { cerr << "Password must be between 3 and 128 characters long. Try again\n"; continue; } strcpy (c, a); #if defined(__WIN32__) cerr << "Re-enter password: "; char b[129]; cin.getline(b, 128); #else char *b = getpass("Re-enter password:"); #endif if ((strcmp (c, b)) == 0) { password_ok = 1; break; } else { cerr << "Passwords didn't match. Try again.\n"; } } if (!password_ok) { cerr << "Failed to capture password." << endl; return -1; } char* p = c; while (*p != 0) { cerr << "char:" << *p << endl; p++; } char *salt = "Tp"; char *pw = crypt (c, salt); cout << pw << "\n"; return 0; }