- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Function to Check UNIX Passwords
To verify UNIX password, we should use the crypt module. It has crypt(3) routine. It is basically one-way hash function based on the modified DES algorithm.
To use the crypt module, we should import it using.
Method crypt.crypt(word, salt)
This method takes two arguments. The first one is the word and second one is salt. The word is basically the user password, which is given in the prompt. The salt is a random string. It is used to perturb the DES Algorithm in one of 4096 ways. The salt contains only Upper-case, Lower-case, Numeric values and ‘/’, ‘.’ characters.
This method returns a hashed password as string.
import crypt, getpass, spwd def check_pass(): username = input("Enter The Username: ") password = spwd.getspnam(username).sp_pwdp if password: clr_text = getpass.getpass() return crypt.crypt(clr_text, password) == password else: return 1 if check_pass(): print("The password matched") else: print("The password does not match")
(Run this Program with root level permission)
$ sudo python3 example.py Enter The Username: unix_user Password: The password matched
- Python Interfaces to Unix databases (dbm)
- Python Interface to UNIX syslog library routines
- How to convert Python date to Unix timestamp?
- Unix filename pattern matching in Python
- Unix filename pattern matching in Python (fnmatch)
- How to convert unix timestamp string to readable date in Python?
- Program to find the resolved Unix style path in Python
- Encrypting Passwords in PHP
- How to generateencryptdecrypt random passwords in linux
- Is there any whoami function or command in MySQL like UNIX?
- Unix style pathname pattern expansion in Python (glob)
- How Do Hackers Steal Passwords?
- How to generate passwords with varying lengths in R?
- How to compare two encrypted (bcrypt) passwords in Laravel?
- Convert MySQL timestamp to UNIX Timestamp?