1/* pwcheck_getspnam.c -- check passwords using getspnam()
2   $Id: pwcheck_getspnam.c,v 1.2 2004/07/07 22:53:07 snsimon Exp $
3
4Copyright 1998, 1999 Carnegie Mellon University
5
6                      All Rights Reserved
7
8Permission to use, copy, modify, and distribute this software and its
9documentation for any purpose and without fee is hereby granted,
10provided that the above copyright notice appear in all copies and that
11both that copyright notice and this permission notice appear in
12supporting documentation, and that the name of Carnegie Mellon
13University not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
16
17CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
18THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR
20ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
22ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
23OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24******************************************************************/
25
26#include <shadow.h>
27
28extern char *crypt();
29
30char *pwcheck(userid, password)
31char *userid;
32char *password;
33{
34    struct spwd *pwd;
35
36    pwd = getspnam(userid);
37    if (!pwd) {
38	return "Userid not found";
39    }
40
41    if (strcmp(pwd->sp_pwdp, crypt(password, pwd->sp_pwdp)) != 0) {
42	return "Incorrect password";
43    }
44    else {
45	return "OK";
46    }
47}
48