Skip to content

Commit fe92ff2

Browse files
author
CodesForge
committed
fix: fixed argon service
1 parent 0964e52 commit fe92ff2

File tree

4 files changed

+36
-23
lines changed

4 files changed

+36
-23
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "secure-python-utils"
7-
version = "0.1.4"
7+
version = "0.1.5"
88
description = "Best security utils for FastAPI: Argon2, rate limiting, logging"
99
readme = "README.md"
1010
authors = [{name = "CodesForge", email = "vkmgscarf4@gmail.com"}]

secure_python_utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
logged = LoggerConfig.logged
88

99
__all__ = [
10-
"PasswordService",
10+
"hash_service",
1111
"get_logger",
1212
"logged",
1313
"RateLimiter",
1414
"settings",
1515
]
1616

17-
__version__ = "0.1.0"
17+
__version__ = "0.1.5"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .argon2 import PasswordService
22

3-
__all__ = ["PasswordService"]
3+
__all__ = ["hash_service"]
Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
from __future__ import annotations
2-
from ..settings import settings
32

43
from argon2 import PasswordHasher
54
from argon2.exceptions import VerifyMismatchError
65

7-
class PasswordService:
8-
_ph: PasswordHasher | None = None
6+
from typing import Optional
7+
8+
class hash_service:
9+
def __init__(
10+
self,
11+
time_cost: int = 6,
12+
parallelism: int = 8,
13+
hash_len: int = 32,
14+
salt_len: int = 16,
15+
memory_cost: int = 102400,
16+
):
17+
self._memory_cost = memory_cost
18+
self._salt_len = salt_len
19+
self._hash_len = hash_len
20+
self._parallelism = parallelism
21+
self._time_const = time_cost
22+
self._ph: Optional[PasswordHasher] = None
923

10-
@classmethod
11-
def ph(cls) -> PasswordHasher:
12-
if cls._ph is None:
13-
cls._ph = PasswordHasher(
14-
time_cost=settings.argon2_time_cost,
15-
parallelism=settings.argon2_parallelism,
16-
hash_len=settings.argon2_hash_len,
17-
salt_len=settings.argon2_salt_len,
18-
memory_cost=settings.argon2_memory_cost,
24+
@property
25+
def ph(self) -> PasswordHasher:
26+
if self._ph is None:
27+
self._ph = PasswordHasher(
28+
time_cost=self._time_const,
29+
parallelism=self._parallelism,
30+
hash_len=self._hash_len,
31+
salt_len=self._salt_len,
32+
memory_cost=self._memory_cost,
1933
)
20-
return cls._ph
34+
return self._ph
2135

22-
@classmethod
23-
def hash(cls, password: str) -> str:
24-
return cls.ph().hash(password)
36+
async def hash(self, password: str) -> str:
37+
return self.ph.hash(password)
2538

26-
@classmethod
27-
def verify(cls, hashed: str, password: str) -> bool:
39+
async def verify(self, hash: str, password: str) -> bool:
2840
try:
29-
return cls.ph().verify(hashed, password)
41+
return self.ph.verify(hash, password)
3042
except VerifyMismatchError:
3143
return False
44+

0 commit comments

Comments
 (0)