Skip to content

Commit d52e51f

Browse files
Smart Passwords Library (smartpasslib) v2.0.0
1 parent 4d4d072 commit d52e51f

File tree

27 files changed

+681
-445
lines changed

27 files changed

+681
-445
lines changed

README.md

Lines changed: 312 additions & 68 deletions
Large diffs are not rendered by default.

data/images/cov.png

-36.3 KB
Loading

data/requirements/develop_requirements.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "smartpasslib"
7-
version = "1.2.1"
7+
version = "2.0.0"
88
description = "Cross-platform library for generating smart passwords."
99
authors = [
10-
{name = "A.A Suvorov", email = "smartlegiondev@gmail.com"}
10+
{name = "Alexander Suvorov", email = "smartlegiondev@gmail.com"}
1111
]
1212
license = "BSD-3-Clause"
1313
readme = "README.md"

smartpasslib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from smartpasslib.managers.smart_password_manager import SmartPasswordManager
1212
from smartpasslib.masters.smart_password_master import SmartPasswordMaster
1313
from smartpasslib.smart_passwords.smart_password import SmartPassword
14-
__version__ = '1.2.1'
14+
__version__ = '2.0.0'
1515
__author__ = 'A.A. Suvorov'
1616
__all__ = [
1717
"SmartPasswordMaster",

smartpasslib/factories/smart_password_factory.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33

44

55
class SmartPasswordFactory:
6-
"""Factory class for creating SmartPassword instances."""
6+
"""
7+
Factory class for creating SmartPassword objects.
8+
"""
79

810
@classmethod
9-
def create_smart_password(cls, login: str, key: str, length: int) -> SmartPassword:
11+
def create_smart_password(cls, public_key: str, description: str, length: int = 12) -> SmartPassword:
1012
"""
1113
Create a new SmartPassword instance.
1214
1315
Args:
14-
login (str): User login.
15-
key (str): Generation key.
16-
length (int): Password length.
16+
public_key: Public key for verifying secret phrase knowledge
17+
description: Service/account description
18+
length: Password length (default: 12)
1719
1820
Returns:
19-
SmartPassword: New SmartPassword instance.
21+
SmartPassword: Configured smart password object
2022
"""
21-
return SmartPassword(login=login, key=key, length=length)
23+
return SmartPassword(public_key=public_key, description=description, length=length)

smartpasslib/generators/base.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44

55

66
class BasePasswordGenerator:
7-
"""Basic password generator with letters, digits, and symbols."""
7+
"""
8+
Generator for basic random passwords.
9+
"""
810

911
letters = string.ascii_letters
1012
digits = string.digits
1113
symbols = '!@#$%&^_'
1214

1315
@classmethod
14-
def generate(cls, length: int = 10) -> str:
16+
def generate(cls, length: int = 12) -> str:
1517
"""
16-
Generates a password of the specified length.
18+
Generate a random password of specified length.
1719
1820
Args:
19-
length (int): Password length (default: 10).
21+
length: Length of password to generate (default: 12)
2022
2123
Returns:
22-
str: Generated password.
24+
str: Randomly generated password
2325
"""
2426
symbols_string = cls.letters + cls.digits + cls.symbols
2527
return ''.join((random.choice(symbols_string) for _ in range(length)))

smartpasslib/generators/code.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44

55

66
class CodeGenerator:
7+
"""
8+
Generator for secure codes with guaranteed character sets.
9+
"""
10+
711
special_chars = "!@#$%^&*"
812

913
@classmethod
1014
def generate(cls, length: int = 6) -> str:
15+
"""
16+
Generate a secure code with at least one character from each required set.
17+
18+
Args:
19+
length: Code length, minimum 4 characters
20+
21+
Returns:
22+
str: Generated code
1123
24+
Raises:
25+
ValueError: If length is less than 4
26+
"""
1227
if length < 4:
1328
raise ValueError("The code length must be at least 4 characters..")
1429

smartpasslib/generators/hash.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

44

55
class HashGenerator:
6-
"""SHA3-512 hash generator."""
6+
"""
7+
Generator for cryptographic hash values.
8+
"""
79

810
@classmethod
911
def generate(cls, text: str) -> str:
1012
"""
11-
Generates a SHA3-512 hash for the given text.
13+
Generate SHA3-512 hash for the given text.
1214
1315
Args:
14-
text (str): Input string to hash.
16+
text: Input text to hash
1517
1618
Returns:
17-
str: Hexadecimal representation of the hash.
19+
str: Hexadecimal SHA3-512 hash
1820
"""
1921
text = str(text)
2022
sha = hashlib.sha3_512(text.encode('utf-8'))

smartpasslib/generators/key.py

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,71 @@
33

44

55
class SmartKeyGenerator:
6-
"""Key generator based on iterative hashing."""
6+
"""
7+
Generator for cryptographic keys from secret phrases.
8+
"""
79

810
@classmethod
9-
def _create_key(cls, login: str = '', secret: str = '', public_step: int = 15) -> str:
11+
def _create_key(cls, secret, steps: int = 30) -> str:
1012
"""
11-
Internal method for key generation.
12-
13-
Args:
14-
login (str): User login.
15-
secret (str): Secret string.
16-
public_step (int): Number of hashing iterations.
17-
18-
Returns:
19-
str: Generated key.
13+
Internal method to create a key through iterative hashing.
2014
"""
21-
login_hash = cls.get_hash(text=login)
22-
secret_hash = cls.get_hash(text=secret)
23-
all_hash = cls.get_hash(text=login_hash + secret_hash)
24-
for _ in range(public_step):
25-
temp_hash = cls.get_hash(all_hash)
26-
all_hash = cls.get_hash(all_hash + temp_hash + secret_hash)
15+
all_hash = cls.get_hash(secret)
16+
for i in range(steps):
17+
temp_string = f"{all_hash}:{secret}:{i}"
18+
all_hash = cls.get_hash(temp_string)
2719
return cls.get_hash(all_hash)
2820

2921
@classmethod
30-
def generate_public_key(cls, login: str = '', secret: str = '') -> str:
22+
def generate_public_key(cls, secret) -> str:
3123
"""
32-
Generates a public key.
24+
Generate a public verification key from secret phrase.
3325
3426
Args:
35-
login (str): User login.
36-
secret (str): Secret string.
27+
secret: Secret phrase
3728
3829
Returns:
39-
str: Public key.
30+
str: Public key for verification
4031
"""
41-
return cls._create_key(login, secret, 60)
32+
return cls._create_key(secret=secret, steps=60)
4233

4334
@classmethod
44-
def generate_private_key(cls, login: str = '', secret: str = '') -> str:
35+
def generate_private_key(cls, secret) -> str:
4536
"""
46-
Generates a private key.
37+
Generate a private key from secret phrase.
4738
4839
Args:
49-
login (str): User login.
50-
secret (str): Secret string.
40+
secret: Secret phrase
5141
5242
Returns:
53-
str: Private key.
43+
str: Private key
5444
"""
55-
return cls._create_key(login, secret, 30)
45+
return cls._create_key(secret=secret, steps=30)
5646

5747
@classmethod
58-
def check_key(cls, login: str = '', secret: str = '', key: str = '') -> bool:
48+
def check_key(cls, secret: str, key: str) -> bool:
5949
"""
60-
Verifies if a key matches the given login and secret.
50+
Verify if a key matches the secret phrase.
6151
6252
Args:
63-
login (str): User login.
64-
secret (str): Secret string.
65-
key (str): Key to verify.
53+
secret: Secret phrase to check
54+
key: Key to verify
6655
6756
Returns:
68-
bool: True if the key is valid, False otherwise.
57+
bool: True if key was generated from this secret
6958
"""
70-
return cls.generate_public_key(login=login, secret=secret) == key
59+
return cls.generate_public_key(secret=secret) == key
7160

7261
@classmethod
7362
def get_hash(cls, text: str = '') -> str:
7463
"""
75-
Generates a hash for the given text.
64+
Generate SHA3-512 hash of text.
7665
7766
Args:
78-
text (str): Input string.
67+
text: Input text
7968
8069
Returns:
81-
str: Hash of the input string.
70+
str: Hexadecimal hash
8271
"""
8372
text = str(text)
8473
return HashGenerator.generate(str(text.encode('utf-8')))

0 commit comments

Comments
 (0)