2005-04-06 23:59

Simple password validation

I am writing a sort of web-based admin tool for a client, and I had this problem: How do you validate a system user from a script?

Well, this is how:

def validPass(name,password):
     p=os.popen('/usr/bin/checkpassword-pam -s login -- /bin/true 3<&0','w')
     s='%s\000%s\000xxx\000'%(name,password)
     p.write(s)
     r=p.close()
     if r==None: #Success
             return True
     else:
             return False

Just get checkpassword-pam from somewhere.

Or, if you use some other sort of authentication scheme, some other checkpassword. They are meant for qmail, but they are very handy :-)

Comments

Comments powered by Disqus

Contents © 2000-2018 Roberto Alsina