Skip to main content

Ralsina.Me — Roberto Alsina's website

Simple password validation

I am writ­ing a sort of we­b-based ad­min tool for a clien­t, and I had this prob­lem: How do you val­i­date a sys­tem us­er from a scrip­t?

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 check­pass­word-­pam from some­where.

Or, if you use some oth­er sort of au­then­ti­ca­tion scheme, some oth­er check­pass­word. They are meant for qmail, but they are very handy :-)

Grohl / 2006-04-03 16:19:



what is 'os' object ?

Roberto Alsina / 2006-04-03 16:20:

it's python's os module. Provides stuff like system/popen/exec, among many others.



It's in the standard library.

sergio / 2006-04-03 16:21:

Looks like a hack, but it's pretty simple. I'd like to have something like that in java. :)

Roberto Alsina / 2006-04-03 16:21:

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:



http://jpam.sourceforge.net/documentation/


Contents © 2000-2023 Roberto Alsina