示例#1
0
 def create(self):
     with Connenct() as cursor:
         query = "INSERT INTO History(what,who) VALUES ('create user','" + self.session_id + "')"
         cursor.execute(query)
         query = "INSERT INTO User(login,password,laws,blocked) VALUES ('" + self.login + "','" + self._password + "','" + str(
             self._laws) + "','" + str(self.__blocked) + "')"
         cursor.execute(query)
示例#2
0
 def authorization(self, login, password):
     self.login = login
     self._password = password
     with Connenct() as cursor:
         query = "SELECT laws FROM User WHERE login='******' AND password= '******'"
         response = cursor.execute(query)
         tempDict = createDict(response)
         from datetime import datetime
         self.session_id = str(tempDict.values()[0]) + ' ' + str(
             datetime.now()) + ' ' + self.login
         self._law = tempDict.values()[0]
示例#3
0
def identification(login, password, context):
    users_list = [line.rstrip('\n') for line in open('base.txt')]
    for user in users_list:
        data = context.crypt.decryptStringENC(user)
        if login and password in data:
            with Connenct() as cursor:
                query = "SELECT login FROM User WHERE password='******'AND login='******'" % (
                    password, login)
                try:
                    response = cursor.execute(query)
                except OperationalError:
                    raise SystemExit("You just tried use sql injection")
                logins = createDict(response)
                if logins is None:
                    return False
                token = list()
                token.append(login)
                if logins.values() == token:
                    query = "SELECT laws FROM User WHERE login='******' AND password= '******'" % (
                        login, password)
                    response = cursor.execute(query)
                    logs = createDict(response)
                    admin_laws = list()
                    admin_laws.append(1)
                    if logs.values() == admin_laws:
                        user = User(login, password, 1)
                        context.set_user('admin', user)
                        return context
                    else:
                        query = "SELECT blocked FROM User WHERE password='******'AND login='******'"
                        response = cursor.execute(query)
                        logs = createDict(response)
                        blocked = list()
                        blocked.append(1)
                        if logs.values() == blocked:
                            raise SystemExit(
                                "You are blocked by admin, please contact him")
                        user = User(login, password, 0)
                        context.set_user('common', user)
                        return context
                else:
                    return False
示例#4
0
 def user_blocker(self, id, value):
     with Connenct() as cursor:
         if value == 'block':
             query = "INSERT INTO History(what,who) VALUES ('block user" + str(
                 id) + "','" + self.session_id + "')"
             cursor.execute(query)
             query = "UPDATE User SET blocked='1' WHERE id='" + str(
                 id) + "'"
             cursor.execute(query)
             return self
         elif value == 'unblock':
             query = "INSERT INTO History(what,who) VALUES ('unblock user" + str(
                 id) + "','" + self.session_id + "')"
             cursor.execute(query)
             query = "UPDATE User SET blocked='0' WHERE id='" + str(
                 id) + "'"
             cursor.execute(query)
             return self
         else:
             raise StandardError
示例#5
0
 def change_own_password(self):
     global new_password1, new_password2, old_password
     while True:
         try:
             old_password = input("Enter old password:"******"Enter new valid password:"******"Repeat new password:"******"Print valid values"
         if not password_is_valid(new_password1):
             from termcolor import colored
             print colored("Password isn't valid", 'red')
         elif new_password1 == new_password2 and old_password == self._password:
             with Connenct() as cursor:
                 query = "INSERT INTO History(what,who) VALUES ('change own password','" + self.session_id + "')"
                 cursor.execute(query)
                 query = "UPDATE User SET password='******' WHERE login='******';"
                 cursor.execute(query)
                 print "Successful change"
                 return True
         else:
             pass
示例#6
0
def view_user_list():
    with Connenct() as cursor:
        query = "SELECT id,login,password,blocked,laws FROM User;"
        response = cursor.execute(query)
        tempDict = response.fetchall()
        return tempDict
def count_in_base():
    with Connenct() as cursor:
        query = "SELECT id,login,password,blocked,laws FROM User;"
        response = cursor.execute(query)
        return len(response.fetchall())