2

Sorry if the answer to this question may be obvious, but I'm very new to Python (just first started reading a small document about the differing structure and other things from C this morning). While practicing, I decided to make an ATM. However, something weird in the verification process happened, where it compares the input password to the password in a .txt file representing a user database. Despite the two strings are perfectly equal (and yes, I've checked the type, both are class str), my script is completely failing to compare the two correctly! I'm looking and I'm sure I'm missing something obvious, but I just can't find it.

Here's the relevant bits:

class MockUserInterface:
    def __init__(self):
        ccn = input('Enter your Credit Card Number --> ')
        password = input('Enter the corresponding password --> ')
        self.db = MockDatabase()
        self.processUser(ccn, password)

processUser(self, ccn, password) passes ccn and password to VerifyUser to get a False|dictionary value...

class MockDatabase:
    def __init__(self):
        self.initdata = open('D:/users.txt', 'r')
        self.data = {}
        line = 0
        for user in self.initdata:
            line += 1
            splitted_line = user.split(',')
            self.data[splitted_line[0]] = {'Name' : splitted_line[1], 'Password' : splitted_line[2], 'Balance' : splitted_line[3], 'id' : line}
        self.initdata.close()

    def verifyUser(self, ccn, password):
        if ccn in self.data:
            if ccn == self.data[ccn]['Password']:
                return self.data[ccn]
            else:
                print(password, self.data[ccn]['Password'])
        else:
            print(self.data)

The users.txt looks like this:

13376669999,Jack Farenheight,sh11gl3myd1ggl3d4ggl3,90001
10419949001,Sardin Morkin,5h1s1s2w31rd,90102
12345678900,Johnathan Paul,w3ll0fh1sm4j3sty,91235
85423472912,Jacob Shlomi,s3ndm35h3b11m8,-431
59283247532,Anon Tony,r34lp0l1t1k,-9999

After running the script, the output is:

C:\Python33\python.exe D:/PythonProjects/ATM(caspomat).py
Enter your Credit Card Number --> 13376669999
Enter the corresponding password --> sh11gl3myd1ggl3d4ggl3
sh11gl3myd1ggl3d4ggl3 sh11gl3myd1ggl3d4ggl3

Process finished with exit code 0

Again, sorry if the answer is obvious or I'm not giving enough info!

2
  • What does the ProcessUser method look like in your MockDatabase class. This is where the error is occuring Commented Sep 1, 2013 at 16:17
  • @mou, In fact OP removed his own post, I rolled it back since it looks like an accidential action Commented Sep 22, 2013 at 10:01

1 Answer 1

9

You are comparing ccn to the password - not the password arg with the user's stored password...

if ccn == self.data[ccn]['Password']:

should be

if password == self.data[ccn]['Password']:
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.