root/gsdl/trunk/common-src/src/getpw/getpw.cpp @ 18493

Revision 18493, 2.6 KB (checked in by davidb, 11 years ago)

Increased password limit to 128, and made to loop stop after three attempts

  • Property svn:keywords set to Author Date Id Revision
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// use the standard namespace
33#if !defined (GSDL_NAMESPACE_BROKEN)
34#if defined(GSDL_USE_OBJECTSPACE)
35using namespace ospace::std;
36#else
37using namespace std;
38#endif
39#endif
40
41
42// include crypt
43#if defined(__WIN32__)
44#include "crypt.h"
45#else
46
47#include "config.h"
48#if defined(HAVE_CRYPT_H)
49#include <crypt.h>
50#endif
51
52#if defined(HAVE_UNISTD_H)
53#include <unistd.h>
54#endif
55/* we are probably in trouble if we have neither crypt.h or unistd.h,
56   but for now we'll do nothing about it... */
57
58#endif  /* not WIN32 */
59
60#if defined(GSDL_USE_OBJECTSPACE)
61#  include <ospace\std\iostream>
62#elif defined(GSDL_USE_IOS_H)
63#  include <iostream.h>
64#else
65#  include <iostream>
66#endif
67
68#include <string.h>
69#include <pwd.h>
70
71int main (int argc, char *argv[]) {
72
73  int password_ok = 0;
74  char c[10];
75  int i;
76 
77  for (i=0; i<3; i++)  {
78    char *a = getpass("Enter password:");
79    int len = strlen (a);
80    if (len < 3 || len > 128) {
81      cerr << "Password must be between 3 and 128 characters long. Try again\n";
82      continue;
83    }
84
85    strcpy (c, a);
86
87    char *b = getpass("Re-enter password:"); 
88
89    if ((strcmp (c, b)) == 0) {
90      password_ok = 1;
91      break;
92    }
93    else {
94      cerr << "Passwords didn't match. Try again.\n";
95    }
96  }
97
98  if (!password_ok) {
99    cerr << "Failed to capture password." << endl;
100    return -1;
101  }
102
103  char *salt = "Tp";
104  char *pw = crypt (c, salt);
105
106  cout << pw << "\n";
107 
108  return 0;
109}
Note: See TracBrowser for help on using the browser.