예제 #1
0
 def change_pass_of_client(self, new_pass, logged_user):
     validate_client(logged_user)
     self.__validate_logged_user(logged_user)
     validate_password(new_pass, logged_user.get_username())
     self.cursor.execute(UPDATE_PASSWORD_OF_CLIENT,
                         (encode(new_pass), logged_user.get_id()))
     self.db.commit()
예제 #2
0
    def login_client(self, username, password):
        # import ipdb; ipdb.set_trace()
        self.__validate_existing_username(username)

        now = datetime.datetime.now()
        time_banned = self.__get_time_bannded(username)
        if now < time_banned:
            raise ValueError("You are banned! ")

        time_for_wrong_tries = self.__get_time_for_wrong_tries(username)
        self.cursor.execute(GET_CLIENT_DATA, (username, encode(password)))
        user = self.cursor.fetchone()
        # import ipdb; ipdb.set_trace()
        FF = now >= time_for_wrong_tries
        if now >= time_for_wrong_tries:
            if (user):
                return Client(user[0], username, user[1], user[2])
            else:
                one_minute = (now + datetime.timedelta(minutes=1)
                              ).strftime("%Y-%m-%d %H:%M:%S")
                self.cursor.execute(SET_TIME_FOR_WRONG_TRIES,
                                    (one_minute, username))
                self.cursor.execute(SET_COUNT_TRIES, (1, username))
                self.db.commit()
                return False
        else:
            if (user):
                self.cursor.execute(SET_COUNT_TRIES, (0, username))
                self.cursor.execute(
                    SET_TIME_FOR_WRONG_TRIES,
                    (now.strftime("%Y-%m-%d %H:%M:%S"), username))
                self.db.commit()
                return Client(user[0], username, user[1], user[2])
            else:
                count = self.__get_count_tries(username)
                if count == 4:
                    self.cursor.execute(SET_COUNT_TRIES, (0, username))
                    self.cursor.execute(
                        SET_TIME_FOR_WRONG_TRIES,
                        (now.strftime("%Y-%m-%d %H:%M:%S"), username))
                    five_min = (now + datetime.timedelta(minutes=5)
                                ).strftime("%Y-%m-%d %H:%M:%S")
                    self.cursor.execute(SET_TIME_BANNED, (five_min, username))
                    self.db.commit()
                else:
                    self.cursor.execute(SET_COUNT_TRIES, (count + 1, username))
                    self.db.commit()
                return False
예제 #3
0
def encode():
    code = None
    encode_failed = False

    info = {}
    for field in value_fields:
        if field not in request.args:
            continue

        try:
            value = int(request.args.get(field), 0)
        except:
            encode_failed = True
            continue

        if value < 0 or value > value_fields[field]:
            encode_failed = True
            continue
        info[field] = value
    if "team" in request.args:
        team = request.args.get("team")
        if len(team) > 12:
            encode_failed = True
        else:
            info["team"] = []
            for char in team:
                if char in romdata.charmap_text:
                    info["team"].append(romdata.charmap_text.index(char))
                else:
                    encode_failed = True
                    break

    if not encode_failed:
        if validate_info(info):
            code = password.encode(info)
        else:
            encode_failed = True

    return render_password(code, info=info, encode_failed=encode_failed)
예제 #4
0
 def register_new_client(self, username, password):
     validate_username(username)
     validate_password(password, username)
     self.cursor.execute(ADD_CLIENT, (username, encode(password)))
     self.db.commit()
예제 #5
0
def render_password(code,
                    revive=False,
                    password_input=None,
                    info=None,
                    **kwargs):
    infores = {}
    inforev = {}
    info_text = None
    warnings = None
    password_output = None
    password_revive = None

    if code:
        info = password.decode(code)
        info_text = escape(password.print_info(info))
        warnings = get_warnings(info)
        password_input = escape(password_val2char(code))
        password_output = escape(password_html(code))
        if info["type"] == 0 and revive:
            inforev = {
                "timestamp": int(datetime.now().timestamp()),
                "unk1": 0,
                "team": [romdata.charmap_text.index(x) for x in "Passwd tool"],
                "type": 1,
                "revive": info["revive"]
            }
            password_revive = escape(password_html(password.encode(inforev)))

    if info:
        if "type" in info and info["type"] == 1:
            inforev = info
        else:
            infores = info
        if "revive" in info:
            inforev["revive"] = "0x%08X" % info["revive"]

    for info in (infores, inforev):
        if "team" in info:
            team = ""
            for char in info["team"]:
                if char == 0:
                    break
                if char < 402:
                    team += romdata.charmap_text[char]
                else:
                    team += "★"
            info["team"] = team

        if "timestamp" not in info:
            info["timestamp"] = int(datetime.now().timestamp())
        if "team" not in info:
            info["team"] = "Passwd tool"

    return render_template("index.html",
                           romdata=romdata.romdata,
                           named=named_fields,
                           value=value_fields,
                           infores=infores,
                           inforev=inforev,
                           info_text=info_text,
                           warnings=warnings,
                           password_input=password_input,
                           password_output=password_output,
                           password_revive=password_revive,
                           **kwargs)
예제 #6
0
 def test_register_new_client(self):
     self.manager.cursor.execute(GET_CLIENT_DATA,
                                 ('Dinko', encode('D123?Inko123')))
     count = len(self.manager.cursor.fetchall())
     self.assertEqual(count, 1)
예제 #7
0
 def __add_user(self, username, password, age):
     validate_username(username)
     validate_password(password)
     validate_age(age)
     self.cursor.execute(ADD_USER, (username, encode(password), age))
     self.users_ids.append(self.cursor.lastrowid)
예제 #8
0
 def __validate_password_of_user(self, user_id, password):
     self.cursor.execute(PASSWORD_OF_USER, (user_id, ))
     user_password = self.cursor.fetchone()["PASSWORD"]
     if encode(password) != user_password:
         raise ValueError("Wrong password for this username.")