how to let crypt module only work when paramater values are identical to the given ones?

I've been trying to figure out how i can let this code only work when the values match the given ones through an cli on for example, ubuntu. The code works, but it still says the password matches the orginal one when i give another pass/hash than test/npDnXtpN5py4. anyone who can help? regards.

import os, sys
import getopt
import pwd
import crypt

def checkPassword(pswd, cpswd):
    """ Check if `cpwsd` an encrypted version is of `pswd`.
        Return `True` of `False`
        cpswd = 'npDnXtpN5py4U'
        pswd = 'test'
        cryptedpassword = crypt.crypt(pswd, cpswd)
        return cpswd == cryptedpassword
    except KeyError:
        return 0 # no such pw

if __name__ == '__main__':
    opts, args = getopt.getopt(sys.argv[1:], 'V', [])
    if len(args) != 2:
        print('Usage: {} [-v] <cpswd> <pswd>'.format(sys.argv[0]))

    cpswd, pswd = args[0], args[1]
    res = checkPassword(pswd, cpswd)
    if res:
        print("Pass for '{}' is '{}'".format(
            cpswd, pswd))
        print("Pass for '{}' is not '{}'".format(
            cpswd, pswd))

Read more here:

Content Attribution

This content was originally published by Alen at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: