digital adj. Having digits.     peer n. A comrade; a companion; a fellow; an associate. inmotion    
   
Recent Articles
Stop DNSMasq From Forwarding Local Hostnames
Saturday, September 25, 2010
Securing your Wireless LAN
Wednesday, August 18, 2010
Some tips and things you might not know about your wireless network.
Using Different Subversion Client Versions
Wednesday, August 18, 2010
Handling a Subversion Repository URL Change
Sunday, May 3, 2009
If your repository URL changes, you can use the following command to fix existing snapshots.
vfat Mounts Default to Lowercase Shortnames
Tuesday, April 21, 2009
I want a "this is brain-damage" quote from Linus for this mess.
VirtualBox or VMWare Virtual Machine at Login
Sunday, April 12, 2009
How to start a virtual machine in X when a user logs in.
Dialog Progress Bar Through Pipe
Sunday, April 12, 2009
How to use dialog to display a script progress bar and communicate progress to it through a named pipe.
Mount JFFS2 Image
Saturday, October 25, 2008
Example of how to mount a JFFS2 image using mtdblock.

Don't regret things you do, cause at one point what you did was what you wanted.

Projects-Misc Utilities-How to Check...

How to Check a User Password on Linux

Saturday, July 17, 2004 by digitalpeer, updated Saturday, July 31, 2004

This example code will check a user password to see if it is the correct password for a given user. You'll need to link with the crypt lib in order for this to work.
#include <stdlib.h>
#include <stdio.h>

#include <pwd.h>
#include <shadow.h>

/** Grab the shadow password */
struct spwd *getspuid(uid_t pw_uid)
{
  struct spwd *shadow;
  struct passwd *ppasswd;

  if( ((ppasswd = getpwuid(pw_uid)) == NULL)
      || ((shadow = getspnam(ppasswd->pw_name)) == NULL))
    return NULL;

  return shadow;
}

/* given a plaintext password and an encrypted password, check if
 * they match; returns 1 if they match, 0 otherwise.
 */
int check_pass(const char *plainpw, const char *cryptpw)
{
    return strcmp(crypt(plainpw,cryptpw), cryptpw) == 0;
}

Comment Thursday, September 16, 2010 by  elito
PLEASE TELL ME WHERES IS THE crypt lib ???????
Comment Friday, December 2, 2011 by  Tim
/usr/lib/libcrypt.so

Submit Comment to This Article
Please post a comment if you have something to add, find something wrong, or would like more information on the topic at hand. Do not use the comment form to contact the author about unrelated concerns!

Name: Email (optional):
Enter verification number here: