[1493] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * getpw.cpp --
|
---|
| 4 | * A component of the Greenstone digital library software
|
---|
| 5 | * from the New Zealand Digital Library Project at the
|
---|
| 6 | * University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * Copyright (C) 2000 The New Zealand Digital Library Project
|
---|
| 9 | *
|
---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
| 24 | **********************************************************************/
|
---|
| 25 |
|
---|
[2999] | 26 | #define _XOPEN_SOURCE 1
|
---|
| 27 | /* following is for solaris */
|
---|
| 28 | #define _XOPEN_SOURCE_EXTENDED 1
|
---|
| 29 |
|
---|
| 30 | #include "gsdlconf.h"
|
---|
| 31 |
|
---|
| 32 |
|
---|
[1493] | 33 | // include crypt
|
---|
| 34 | #if defined(__WIN32__)
|
---|
| 35 | #include "crypt.h"
|
---|
| 36 | #else
|
---|
[2276] | 37 |
|
---|
| 38 | #include "config.h"
|
---|
[1493] | 39 | #if defined(HAVE_CRYPT_H)
|
---|
| 40 | #include <crypt.h>
|
---|
[2276] | 41 | #endif
|
---|
| 42 |
|
---|
| 43 | #if defined(HAVE_UNISTD_H)
|
---|
[1493] | 44 | #include <unistd.h>
|
---|
| 45 | #endif
|
---|
[2276] | 46 | /* we are probably in trouble if we have neither crypt.h or unistd.h,
|
---|
| 47 | but for now we'll do nothing about it... */
|
---|
[1493] | 48 |
|
---|
[2276] | 49 | #endif /* not WIN32 */
|
---|
| 50 |
|
---|
[1600] | 51 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 52 | # include <ospace\std\iostream>
|
---|
| 53 | #elif defined(GSDL_USE_IOS_H)
|
---|
| 54 | # include <iostream.h>
|
---|
| 55 | #else
|
---|
| 56 | # include <iostream>
|
---|
| 57 | #endif
|
---|
| 58 |
|
---|
[19275] | 59 | // use the standard namespace
|
---|
| 60 | #if !defined (GSDL_NAMESPACE_BROKEN)
|
---|
| 61 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 62 | using namespace ospace::std;
|
---|
| 63 | #else
|
---|
| 64 | using namespace std;
|
---|
| 65 | #endif
|
---|
| 66 | #endif
|
---|
| 67 |
|
---|
| 68 |
|
---|
[1493] | 69 | #include <string.h>
|
---|
[19275] | 70 | //#include <pwd.h>
|
---|
[1493] | 71 |
|
---|
[19275] | 72 |
|
---|
[1493] | 73 | int main (int argc, char *argv[]) {
|
---|
| 74 |
|
---|
[18493] | 75 | int password_ok = 0;
|
---|
[19275] | 76 | char c[129];
|
---|
[18493] | 77 | int i;
|
---|
| 78 |
|
---|
| 79 | for (i=0; i<3; i++) {
|
---|
[19275] | 80 | #if defined(__WIN32__)
|
---|
| 81 | cout << "Enter password (will appear on screen): ";
|
---|
| 82 | char a[129];
|
---|
| 83 | cin.getline(a, 128);
|
---|
| 84 | #else
|
---|
[1493] | 85 | char *a = getpass("Enter password:");
|
---|
[19275] | 86 | #endif
|
---|
| 87 |
|
---|
[1493] | 88 | int len = strlen (a);
|
---|
[18493] | 89 | if (len < 3 || len > 128) {
|
---|
| 90 | cerr << "Password must be between 3 and 128 characters long. Try again\n";
|
---|
[1493] | 91 | continue;
|
---|
| 92 | }
|
---|
[18493] | 93 |
|
---|
[1493] | 94 | strcpy (c, a);
|
---|
[18493] | 95 |
|
---|
[19275] | 96 | #if defined(__WIN32__)
|
---|
| 97 | cout << "Re-enter password: ";
|
---|
| 98 | char b[129];
|
---|
| 99 | cin.getline(b, 128);
|
---|
| 100 | #else
|
---|
[1493] | 101 | char *b = getpass("Re-enter password:");
|
---|
[19275] | 102 | #endif
|
---|
[18493] | 103 |
|
---|
| 104 | if ((strcmp (c, b)) == 0) {
|
---|
| 105 | password_ok = 1;
|
---|
| 106 | break;
|
---|
| 107 | }
|
---|
| 108 | else {
|
---|
| 109 | cerr << "Passwords didn't match. Try again.\n";
|
---|
| 110 | }
|
---|
[1493] | 111 | }
|
---|
| 112 |
|
---|
[18493] | 113 | if (!password_ok) {
|
---|
| 114 | cerr << "Failed to capture password." << endl;
|
---|
| 115 | return -1;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[1493] | 118 | char *salt = "Tp";
|
---|
| 119 | char *pw = crypt (c, salt);
|
---|
| 120 |
|
---|
| 121 | cout << pw << "\n";
|
---|
| 122 |
|
---|
| 123 | return 0;
|
---|
| 124 | }
|
---|