Search code examples
pythonsqlitepeewee

Peewee : How to validate login details on form submit


Currently I am working on the project . I am new python , peewee.

I need to check given login credentials valid or not ?

I searched so many sites to find this ans. But i am getting exact ans what i want ?

Find something i done below :

def process(self):
    email = self.get_argument("username")
    password = self.get_argument("password")
    print Email, Password
    try:
        result = Employee.select().where(Employee.Email_ID == email , Employee.Password == password)
        print 'Query is ', result
        if result == None:
            print 'Failure'
        else:
            print 'Success'
    except Exception as e:
        print(e)
    return self.render_template("index.py")

can you help me out in this. I did wrong? Thanks in advance


Solution

  • When you check result for None in Python try to compare with "is".

    if result is None:
        .....
    

    It is more efficient to just check "reference" to None.

    I think you error is in you where method.

    .where(Employee.Email_ID == email , Employee.Password == password)
    

    Maybe,

    .where(Employee.Email_ID = email , Employee.Password = password)