Using Crypt Command

Using Crypt Command

Post by Dean Thomps » Sun, 16 Apr 1995 04:00:00



G'day,

  I was wondering whether somebody could please help me clarify the call
crypt and what is returns.  I checked the man page and it seemed to pass
a code and the word to encrypt and it returned a pointer to the encrypted
string.  I want to build a program which checks a password entered
against the system passwd file.  Is the following call correct:

  encrypted = crypt("HELLO");

  I don't know.  Any suggestions would be greatly apprreicated.

  I would prefer all my mail to be directed to:

Thanking you in advance,

Dean Thompson

--

--
_____________________________________________________________________________





+------------------------------+--------------------------------------------+

 
 
 

Using Crypt Command

Post by Patrick Horg » Tue, 18 Apr 1995 04:00:00



|> G'day,
|>
|>   I was wondering whether somebody could please help me clarify the call
|> crypt and what is returns.  I checked the man page and it seemed to pass
|> a code and the word to encrypt and it returned a pointer to the encrypted
|> string.  I want to build a program which checks a password entered
|> against the system passwd file.  Is the following call correct:
|>
|>   encrypted = crypt("HELLO");
|>
|>   I don't know.  Any suggestions would be greatly apprreicated.
|>
|>   I would prefer all my mail to be directed to:

|>
|> Thanking you in advance,
|>
|> Dean Thompson

You're welcome...you can abstract out the call to cracklib from the code
below.

Patrick
~~~~~~~~~~~~~~~~~ cut here for code example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <pwd.h>

#define TRUE 1
#define FALSE 0

main(argc,argv)
int argc;
char **argv;
{
  char salt[3];
  char crypt_pw[15];
  char uncrypt_pw[256];
  char *crack_msg;
  struct passwd *pw;
  unsigned short fail = FALSE;

  /* Generate a random salt value starting with the current time */

  srandom((int)time(NULL));

  salt[0] = (random()%26) + ((random()&0x1)?'a':'A');
  salt[1] = (random()%26) + ((random()&0x1)?'a':'A');
  salt[2] = '\0';

  do {
    /* Get the new passwd */
    strcpy(uncrypt_pw,getpass("Please enter the new password: "));
    if(strcmp(uncrypt_pw,getpass("Please reenter the new password: ")) != 0){
      fprintf(stderr,"Password not the same.\n");
      fail = TRUE;
    } else {
      if ((crack_msg =
           (char *)FascistCheck(uncrypt_pw, "/usr/local/admin/lib/pw_dict")
           ) != NULL) {
        /* Crackable passwd */
        fprintf(stderr,"That password could be broken because,\n");
        fprintf(stderr,"%s.\n",crack_msg);
        fail = TRUE;
      } else {
        fail = FALSE;
      }
    }

  } while (fail == TRUE);

  printf("%s\n",crypt(uncrypt_pw,salt));

  return(0);

Quote:}

--
   _______________________________________________________________________
  /  These opinions are mine, and not Amdahl's (except by coincidence;).  \
 |                                                       (\                |
 |  Patrick J. Horgan         Amdahl Corporation          \\    Have       |

 |  Phone : (408)992-2779     P.O. Box 3470 M/S 316         \\/    Will    |
 |  FAX   : (408)773-0833     Sunnyvale, CA 94088-3470     _/\\     Travel |
  \___________________________O16-2294________________________\)__________/

 
 
 

Using Crypt Command

Post by Syed Z Taq » Wed, 19 Apr 1995 04:00:00


You could try this :

---------------------------------------------------------
#include <pwd.h>

int result;
char login[32], pwd[32];
struct passwd *pswd;

/* scan for login and password (you can use getpass system call to prompt
   for a password */
pswd = getpwnam(login);
result = strcmp(pswd->pw_passwd, crypt(pwd, pswd->pw_passwd);

------------------------------------------------------------

: G'day,

:   I was wondering whether somebody could please help me clarify the call
: crypt and what is returns.  I checked the man page and it seemed to pass
: a code and the word to encrypt and it returned a pointer to the encrypted
: string.  I want to build a program which checks a password entered
: against the system passwd file.  Is the following call correct:

:   encrypted = crypt("HELLO");

:   I don't know.  Any suggestions would be greatly apprreicated.

:   I would prefer all my mail to be directed to:

: Thanking you in advance,

: Dean Thompson

: --

: --
: _____________________________________________________________________________





: +------------------------------+--------------------------------------------+

 
 
 

1. unix crypt() vs. AIX crypt()


Yeah, this is quite cool. Which scheme is the default?

--
-----------------------------------------------------------------------------
Thomas H. Ptacek                                        Secure Networks, Inc.
-----------------------------------------------------------------------------
http://www.enteract.com/~tqbf                         "mmm... sacrilicious"

2. Suse 6.2 + CD burning, please help !

3. crypt in C++ just like crypt in c library

4. Adding /devices in Solaris 2.51

5. passwd hashing methods Re: unix crypt() vs. AIX crypt()

6. How do you pass file descriptors between processes on linux?

7. Does Linux support crypt(1) and crypt(3)?

8. Solved: Archive Python 4324RP DAT / Solaris 2.3 SS 10

9. Perl(Crypt::DES, Crypt::IDEA)

10. need AIX replacement for system V crypt command

11. Crypt Command

12. User command crypt source

13. crypt command