A Password Box by Python

There's a boring vacation ahead. Time to start the project.
Here: repository link

#Intro

This is a mini-mini project. The functions are shown below.

  • Require a key to log in
  • Add password item
    • App/site name
    • Account/email address
    • Password
    • Adding time (auto-generate)
  • Encrypt the password
  • Store password item
  • Search for password(s)
    • By app/site name
    • By account/email address
  • Update/delete password item
    • Take password item ID as the parameter
    • Display the password item before confirming deletion.
  • Change log in key
  • (2022.1) Generate password. First take a number as password length, and then generate a password with letters, numbers, and symbols.
  • Use curses module to display

#Functions

#Log in key

It's easy.

A key is demanded on the first launch. Double check, then hash it and store it in the database. Every time after that, simply input the key and verify to the main interface.

There should be nothing popping on the screen when inputting the log in key.

  1. With getpass module:

    1
    2
    import getpass
    pwd = getpass.getpass("[PASSWROD]: ") # hide input
  2. With curses.noecho()

#Python Curses Module

Here's the official documentation. Simple as that.

#Encryption, Adding, Deleting, Updating and Searching

Due to the non-reversibility of hashing, another encryption method is needed. Here I shift the ascii code of the character. The offset value is the seconds value of the adding time plus 15. For decryption, shift the ascii backwards, of course.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# offset functions。 only one is enough actually, with changing offset value
def enascii(num: int, offset: int) -> int:
if num - offset >= 33:
return num - offset
else:
return 93 + num - offset

def deascii(num: int, offset: int) -> int:
if num + offset <= 126:
return num + offset
else:
return num + offset - 93

# encryption
def encrypt(psw: str, offset: int) -> str:
encrypt_num = []
for i in psw:
encrypt_num.append(enascii(ord(i), offset + 15))
encrypted = [chr(a) for a in encrypt_num]
return "".join(encrypted)

# decryption, s as encrypted password string
def decrypt(s: str, offset: int) -> str:
pwd = [chr(deascii(ord(a), offset + 15)) for a in s]
return "".join(pwd)

I didn't hide the input when adding password. Some passwords might be complicated. Input them multiple times could be a pain in the **.

When adding password, the box searches for duplicated password items in the database. If there's a password item with the same site/app name and account/email address, the box offers a chance to update password item rather than adding a duplication.

It was hard to use Regx in sqlite3. There's a good solution in StackOverflow which I found suitable for the box.

1
reg = re.compile(expr, re.I)

What's left are just database operations.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import sqlite3
db = sqlite3.connect("database.db")
cur = db.cursor()
cur.execute() # commands here
result1 = cur.fetchall()
result2 = cur.fetchone()
db.commit()
db.close()

create_command = """CREATE TABLE (table) ..."""
add_command = """INSERT INTO (table) (cols) VALUES (value)""" # value must be tuple type
select_command = """SELECT * FROM (table) WHERE ..."""
update_command = """UPDATE (table) SET ... WHERE ..."""
delete_command = """DELETE FROM (table) WHERE ..."""

#To Do

Some are mentioned above. Here're something else.

  • GUI Used curses instead.
  • Use Regx when searching DOne
  • Offer a chance when adding a duplication
  • Interface optimizing
Ipv6 Availability Checking Script on Padavan
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×