How to programmatically (python) authenticate username / password using OS users

I am writing a python program that allows a user to enter it. I do not want to implement my own authentication, but would prefer to use the OS (linux) mechanism. That is, when a user tries to enter my application by entering a username / password pair (which must be a valid OS user), I need to verify the authenticity of this OS pair. How to do it? A subprocess module may be required, but I have not tried.

+4
source share
2 answers

Try using PAM through Python PAM or similar

+5
source

This should be possible if your script reads the /etc/passwd and /etc/shadow files that contain username and password information on a Linux system. Please note that the script must have read access to the files, which, depending on the situation, may or may not be possible.

Here are two good articles explaining the format of these files, which should tell you everything you need to know for your script to read and understand them:

By the way, when it comes to encrypted password, it means that it was encrypted using the DES algorithm. You will probably have to use pyDes or another implementation of the DES algorithm for python so that your script creates an encrypted password that it can compare to a unit in /etc/shadow .

+2
source

All Articles