Skip to content

Commit 20576ab

Browse files
committed
feat: restore password strength validation (#4111)
1 parent 33b0131 commit 20576ab

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

archinstall/lib/menu/util.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from pathlib import Path
22

33
from archinstall.lib.menu.helpers import Input
4-
from archinstall.lib.models.users import Password
4+
from archinstall.lib.models.users import Password, PasswordStrength
5+
from archinstall.lib.output import warn
56
from archinstall.lib.translationhandler import tr
67
from archinstall.tui.ui.result import ResultType
78

@@ -33,6 +34,13 @@ def get_password(
3334
continue
3435

3536
password = Password(plaintext=result.get_value())
37+
38+
strength = PasswordStrength.strength(password.plaintext)
39+
if strength in (PasswordStrength.VERY_WEAK, PasswordStrength.WEAK):
40+
warn(tr('Weak password. Use uppercase, lowercase, numbers, and symbols.'))
41+
elif strength == PasswordStrength.MODERATE:
42+
warn(tr('Moderate password. Add length and more character variety.'))
43+
3644
break
3745

3846
if skip_confirmation:

tests/test_password_strength.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from archinstall.lib.models.users import PasswordStrength
4+
5+
6+
@pytest.mark.parametrize(
7+
'password, expected',
8+
[
9+
('abc', PasswordStrength.VERY_WEAK),
10+
('Abcdef1!', PasswordStrength.WEAK),
11+
('Abcdef1234!', PasswordStrength.MODERATE),
12+
('Abcdef12345!@', PasswordStrength.STRONG),
13+
('', PasswordStrength.VERY_WEAK),
14+
('123456789', PasswordStrength.VERY_WEAK),
15+
('abcdefghijklmnopqr', PasswordStrength.STRONG),
16+
],
17+
)
18+
def test_password_strength(password: str, expected: PasswordStrength) -> None:
19+
assert PasswordStrength.strength(password) == expected

0 commit comments

Comments
 (0)