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 :-)
what is 'os' object ?
it's python's os module. Provides stuff like system/popen/exec, among many others.
It's in the standard library.
Looks like a hack, but it's pretty simple. I'd like to have something like that in java. :)
Hmmm... you don't have something like C's system() in Java? I can see how that would be non-portable :-)
You could hack it with Java-PAM, though: