Skip to content

Instantly share code, notes, and snippets.

@gyuchang
Created May 27, 2011 06:00
Show Gist options
  • Select an option

  • Save gyuchang/994726 to your computer and use it in GitHub Desktop.

Select an option

Save gyuchang/994726 to your computer and use it in GitHub Desktop.
chkpasswd
#include <stdlib.h>
#include <unistd.h>
#include <crypt.h>
#include <stdio.h>
#include <shadow.h>
int main (int argc, char *argv[]) {
char *plain_passwd;
char *crypt_passwd;
char *username;
struct spwd *shadow;
if (argc != 2) {
exit(-1);
}
username = argv[1];
plain_passwd = getpass("password:");
if ((shadow = getspnam(username)) == NULL) {
exit(-1);
}
crypt_passwd = shadow->sp_pwdp;
exit(strcmp(crypt(plain_passwd, crypt_passwd), crypt_passwd));
}
all: chkpasswd.c
gcc -o chkpasswd -l crypt chkpasswd.c
install: all
install -s -m 4755 chkpasswd /usr/local/bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment