source: trunk/gsdl/src/getpw/getpw.cpp@ 1493

Last change on this file since 1493 was 1493, checked in by sjboddie, 24 years ago

added getpw and ability to set initial password from within installation
script

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