#include "kadm_locl.h"

RCSID("$Id: pw_check.c,v 1.10 1996/05/29 23:24:05 assar Exp $");

/*
 * kadm_pw_check
 *
 * pw		: new password or "" if none passed
 * newkey	: key for pw as passed from client
 * strings	: interesting strings to check for
 *
 * returns NULL if pw is ok, else an explanatory string
 */
int
kadm_pw_check(char *pw, des_cblock *newkey, char **pw_msg, 
	      char **strings)
{
  des_cblock pwkey;
  int status=KADM_SUCCESS;
  
  if (pw == NULL || *pw == '\0')
    return status;		/* XXX - Change this later */

#ifndef NO_PW_CHECK
  *pw_msg = NULL;
  des_string_to_key(pw, &pwkey); /* Check AFS string to key also! */
  if (memcmp(pwkey, *newkey, sizeof(pwkey)) != 0)
    {
      /* no password or bad key */
      status=KADM_PW_MISMATCH;
      *pw_msg = "Password doesn't match supplied DES key";
    }
  else if (strlen(pw) < MIN_KPW_LEN)
    {
      status = KADM_INSECURE_PW;
      *pw_msg="Password is too short";
    }
  
#ifdef DICTPATH
  *pw_msg = FascistCheck(pw, DICTPATH, strings);
  if (*pw_msg)
    return KADM_INSECURE_PW;
#endif

  memset(pwkey, 0, sizeof(pwkey));
#endif

  return status;
}
