source: tags/gsdl-2_30a-distribution/gsdl/src/getpw/getpw.cpp@ 2308

Last change on this file since 2308 was 1600, checked in by jrm21, 24 years ago

Sorry - got it right this time. We needed to #define _XOPEN_SOURCE
before we included <iostream>, as both include <features.h>, so the
second time (for unistd.h), _USE_XOPEN doesn't get set and crypt() doesn't
get declared.

Basically, I put the include crypt stuff before the include OBJECTSPACE stuff.
I hope this doesn't break something else (eg Windows compile...)

  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 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// include crypt
27#if defined(__WIN32__)
28#include "crypt.h"
29#else
30#if defined(HAVE_CRYPT_H)
31#include <crypt.h>
32#else
33#define _XOPEN_SOURCE 1
34#include <unistd.h>
35#endif
36#endif
37
38#if defined(GSDL_USE_OBJECTSPACE)
39# include <ospace\std\iostream>
40#elif defined(GSDL_USE_IOS_H)
41# include <iostream.h>
42#else
43# include <iostream>
44#endif
45
46#include <string.h>
47#include <pwd.h>
48
49int main (int argc, char *argv[]) {
50
51 char c[10];
52 while (1) {
53 char *a = getpass("Enter password:");
54 int len = strlen (a);
55 if (len < 3 || len > 8) {
56 cerr << "Password must be between 3 and 8 characters long. Try again\n";
57 continue;
58 }
59 strcpy (c, a);
60 char *b = getpass("Re-enter password:");
61 if ((strcmp (c, b)) == 0) break;
62 else cerr << "Passwords didn't match. Try again.\n";
63 }
64
65 char *salt = "Tp";
66 char *pw = crypt (c, salt);
67
68 cout << pw << "\n";
69
70 return 0;
71}
Note: See TracBrowser for help on using the repository browser.