

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Access to the Shadow Password Database in Python
To access the UNIX shadow password database, we should use the spwd module. We need enough privileges to access this file. The shadow password database entries are like tuple like object.
To use the spwd module, we should import it using −
import spwd
The attributes of the shadow password database are −
Index | Attribute & Description |
---|---|
0 | sp_nam The Login Name or the username of the user |
1 | sp_pwd The Encrypted password |
2 | sp_lstchg Date of last change |
3 | sp_min Minimal number of days between changes of the password |
4 | sp_max Maximum number of days between changes of the password |
5 | sp_warn Warn about number of days to change the password |
6 | sp_inact Number of days after the password expires until block of the account |
7 | p_expire Number of days from 01/01/1997 until account is disabled |
8 | sp_flag Reserved |
Some methods of this module are −
Method spwd.getspnam(name)
This method will return the shadow password database entry for the given user name.
Method spwd.getspall()
This method will return the all available shadow password database entry.
Example Code
import spwd print("Root: " + str(spwd.getspnam('root')) + '\n') #Password detail for root for entry in spwd.getspall(): print("Name: " + entry[0] + "\t\tPassword: " + entry.sp_pwdp)
Output
(To get the desired output, we should run the script in sudo mode)
$ sudo python3 example.py Root: spwd.struct_spwd(sp_namp='root', sp_pwdp='!', sp_lstchg=17778, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1) …….. …….. …….. Name: geoclue Password: * Name: gnome-initial-setup Password: * Name: gdm Password: * Name: unix_user Password: $6$47n9s0Ep$znWkgNtywebHGKq2o6kZKhGOM8ryp8z4/6P6PUE1m.NQ5Erg9aWncNUAGbuNLFNWUO9M9xzKLxRpFGB5md/nu1 Name: mongodb Password: !
- Related Questions & Answers
- Access to the Password Database in Python
- Access to the Group Database in Python
- How To Setup SSH Access Without Password
- Accessing The Unix/Linux password database (pwd)
- Password blacklist table in SAP HANA database
- What is the procedure to access database users in DBMS?
- Password validation in Python
- How to verify the password entered in the JavaFX password field?
- How to simulate the LIMIT MySQL clause with an Access database?
- Managing cross database container access in SAP HANA
- Strong Password Checker in Python
- Python program to check the validity of a Password?
- How do I access SQLite database instance on iPhone
- Set the shadow around the text in CSS
- Add a color to the shadow with CSS