crypt, pwd, getpass - Quick examples using python

crypt() is a weak module because it uses only two letters as a salt which can be easily brute-forced to find the correct plaintext password for the given salt value.
crypt() is used to check the unix password and salt value.
plaintext or cleartext can be chosen randomly or from dictionary words to crack the passwords of the users (function returns once the plaintext and salt values are equal)
crypt.crypt(plaintext, salt) == salt

pwd() is an interesting module which helps to fetch the 7 fields from operating system (password database entries)


 ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  pw_dir
 |      home directory
 |  
 |  pw_gecos
 |      real name
 |  
 |  pw_gid
 |      group id
 |  
 |  pw_name
 |      user name
 |  
 |  pw_passwd
 |      password
 |  
 |  pw_shell
 |      shell program
 |  
 |  pw_uid
 |      user id
----------------------------------------------------------------------

some of the main function in the pwd() are

pwd.getpwuid() returns the values on given uid (user id)
eg:

pwd.getpwuid(501)

pwd.getpwnam() returns the values on given user name 

eg:
pwd.getpwnam('root')

pwd.getpwall() returns all the entries from password database
No parameter needs to passed

pwd.struct_passwd()and pwd.struct_pwent() looks like a similar return types. It returns the str


eg:

getpass() is used to get the password in CLI (both windows and unix) and prints as plain or clear text
eg:
getpass.getpass()

Comments