Linux password manipulation in Python

Steven Taschuk staschuk at telusplanet.net
Tue Mar 18 02:46:04 CET 2003


Quoth Gary Herron:
> How does one deal with encrypted passwords on a Linux system which
> uses shadow passwords?
> 
> The 'crypt' module has an example in its documentation of encrypting a
> password (and then comparing to the contents of the /etc/passwd file),
> but that example explicitly states it does not support shadow
> passwords.  And when I use crypt to encrypt a known password, I do not
> get anything like the contents of the /etc/shadow file.

The example repudiates support for shadow passwords just because
that script doesn't go looking into /etc/shadow (and presumably
the user running it does not have the privileges to), not
necessarily because of a difference in algorithm.

FWIW, crypt.crypt does, on my machine, produce exactly what I find
in the /etc/shadow file:

	# grep ^sjt /etc/shadow
	sjt:1Mm7FdTeEi9TM:12129::::::

	>>> crypt.crypt('foobar', '1M')
	'1Mm7FdTeEi9TM'

(Temporary password for illustrative purposes, obviously.)

-- 
Steven Taschuk                          staschuk at telusplanet.net
"Its force is immeasurable.  Even Computer cannot determine it."
                           -- _Space: 1999_ episode "Black Sun"





More information about the Python-list mailing list