#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <time.h>
#include <crypt.h>
#include <pwd.h>
#include <errno.h>

extern char *safepwd(struct passwd *pwd, char *pass);


int main(int argc, char **argv)
{
	struct passwd   *pw;
	char *user=argv[1];
	char *password=argv[2];
	char *msg;

	if ( argc != 3 )
	{
		fprintf(stderr,"ERROR: not enough arguments\n");
		fprintf(stderr,"USE: %s user password\n", argv[0]);
		fprintf(stderr,"%s will check your password for safety\n", argv[0]);
		return(-2);
	}

	if ( user[0] == '-' )
	{
		user++;

		if (NULL == (pw = getpwnam("nobody")))
		{
		fprintf(stderr,"ERROR: please contact your system administrator\n");
		return (-1);
		}
	}
	else
	{
		if (NULL == (pw = getpwnam(user)))
		{
		fprintf(stderr,"ERROR: there is a problem with \"%s\" account\n");
		fprintf(stderr,"ERROR: please contact your system administrator\n");
		return (-1);
		}
	}

	if ( NULL != ( msg = safepwd( pw, password )))
	{       
		fprintf(stderr,"ERROR: Bad Password\n");
		fprintf(stderr,"ERROR: %s\n",msg);
		return(-1);
	} 
	return 0;
}