source: gsdl/trunk/common-src/src/getpw/getpw.cpp@ 19280

Last change on this file since 19280 was 19280, checked in by ak19, 15 years ago

Removed some debugging output accidentally left in

  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
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
26#define _XOPEN_SOURCE 1
27/* following is for solaris */
28#define _XOPEN_SOURCE_EXTENDED 1
29
30#include "gsdlconf.h"
31
32
33// include crypt
34#if defined(__WIN32__)
35#include "crypt.h"
36#else
37
38#include "config.h"
39#if defined(HAVE_CRYPT_H)
40#include <crypt.h>
41#endif
42
43#if defined(HAVE_UNISTD_H)
44#include <unistd.h>
45#endif
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... */
48
49#endif /* not WIN32 */
50
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
59// use the standard namespace
60#if !defined (GSDL_NAMESPACE_BROKEN)
61#if defined(GSDL_USE_OBJECTSPACE)
62using namespace ospace::std;
63#else
64using namespace std;
65#endif
66#endif
67
68
69#include <string.h>
70//#include <pwd.h>
71
72
73int main (int argc, char *argv[]) {
74
75 int password_ok = 0;
76 char c[129];
77 int i;
78
79 for (i=0; i<3; i++) {
80#if defined(__WIN32__)
81 cerr << "Enter password (will appear on screen): ";
82 char a[129];
83 cin.getline(a, 128);
84#else
85 char *a = getpass("Enter password:");
86#endif
87
88 int len = strlen (a);
89 if (len < 3 || len > 128) {
90 cerr << "Password must be between 3 and 128 characters long. Try again\n";
91 continue;
92 }
93
94 strcpy (c, a);
95
96#if defined(__WIN32__)
97 cerr << "Re-enter password: ";
98 char b[129];
99 cin.getline(b, 128);
100#else
101 char *b = getpass("Re-enter password:");
102#endif
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 }
111 }
112
113 if (!password_ok) {
114 cerr << "Failed to capture password." << endl;
115 return -1;
116 }
117
118
119 char *salt = "Tp";
120 char *pw = crypt (c, salt);
121
122 cout << pw << "\n";
123
124 return 0;
125}
Note: See TracBrowser for help on using the repository browser.