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 .
source share