From 41bccbf9c02fd4709f792ce4e16f2d6afc862867 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 9 Jan 2025 10:23:48 +0800 Subject: [PATCH] perf: update change db lib --- .../check_account/add_to_leak_password.py | 78 +++++++++++++++++++ .../check_account/add_to_leak_password.sh | 3 - .../check_account/leak_passwords.db | 4 +- 3 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 apps/accounts/automations/check_account/add_to_leak_password.py delete mode 100644 apps/accounts/automations/check_account/add_to_leak_password.sh diff --git a/apps/accounts/automations/check_account/add_to_leak_password.py b/apps/accounts/automations/check_account/add_to_leak_password.py new file mode 100644 index 000000000..ab9384ba5 --- /dev/null +++ b/apps/accounts/automations/check_account/add_to_leak_password.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# +import re +import sqlite3 +import sys + + +def is_weak_password(password): + if len(password) < 8: + return True + + # 判断是否只有一种字符类型 + if password.isdigit() or password.isalpha(): + return True + + # 判断是否只包含数字或字母 + if password.islower() or password.isupper(): + return True + + # 判断是否包含常见弱密码 + common_passwords = ["123456", "password", "12345678", "qwerty", "abc123"] + if password.lower() in common_passwords: + return True + + # 正则表达式判断字符多样性(数字、字母、特殊字符) + if ( + not re.search(r"[A-Za-z]", password) + or not re.search(r"[0-9]", password) + or not re.search(r"[\W_]", password) + ): + return True + return False + + +def parse_it(fname): + count = 0 + lines = [] + with open(fname, 'rb') as f: + for line in f: + try: + line = line.decode().strip() + except UnicodeDecodeError: + continue + + if len(line) > 32: + continue + + if is_weak_password(line): + continue + + lines.append(line) + count += 0 + print(line) + return lines + + +def insert_to_db(lines): + conn = sqlite3.connect('./leak_passwords.db') + cursor = conn.cursor() + create_table_sql = ''' + CREATE TABLE IF NOT EXISTS passwords ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + password CHAR(32) + ) + ''' + create_index_sql = 'CREATE INDEX IF NOT EXISTS idx_password ON passwords(password)' + cursor.execute(create_table_sql) + cursor.execute(create_index_sql) + + for line in lines: + cursor.execute('INSERT INTO passwords (password) VALUES (?)', [line]) + conn.commit() + + +if __name__ == '__main__': + filename = sys.argv[1] + lines = parse_it(filename) + insert_to_db(lines) diff --git a/apps/accounts/automations/check_account/add_to_leak_password.sh b/apps/accounts/automations/check_account/add_to_leak_password.sh deleted file mode 100644 index 148447258..000000000 --- a/apps/accounts/automations/check_account/add_to_leak_password.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -# - diff --git a/apps/accounts/automations/check_account/leak_passwords.db b/apps/accounts/automations/check_account/leak_passwords.db index ee0a13a19..7f2c72ae5 100644 --- a/apps/accounts/automations/check_account/leak_passwords.db +++ b/apps/accounts/automations/check_account/leak_passwords.db @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:36a6ac3b65401dbf67cb31ec090e4bad900fc162d092359d9b0a61c177156bad -size 16384 +oid sha256:a2805a0264fc07ae597704841ab060edef8bf74654f525bc778cb9195d8cad0e +size 2547712