Skip to content

Commit d4ddaf6

Browse files
authored
Add zxcvbn to ocflib
Add zxcvbn to ocflib
2 parents 1cb573a + aba1a26 commit d4ddaf6

File tree

12 files changed

+216
-113
lines changed

12 files changed

+216
-113
lines changed

.github/workflows/deploy.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [master]
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
jobs:
13+
deploy:
14+
name: Publish
15+
runs-on: self-hosted
16+
steps:
17+
- name: Checkout branch
18+
uses: actions/checkout@v5.0.0
19+
with:
20+
fetch-depth: 0
21+
- name: Install dependencies
22+
run: |
23+
poetry --version
24+
poetry check --no-interaction
25+
poetry config virtualenvs.in-project true
26+
poetry install --no-interaction
27+
- name: Run tests
28+
run: |
29+
poetry run pytest
30+
- name: Build package
31+
run: |
32+
poetry build --no-interaction
33+
- name: Publish to PyPi
34+
env:
35+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
36+
run: |
37+
poetry config pypi-token.pypi $PYPI_TOKEN
38+
poetry publish --build --no-interaction

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ debian/python3-ocflib/
6262
debian/python3-ocflib.substvars
6363
debian/*.debhelper
6464
/venv
65+
/.venv
6566
.direnv/

Jenkinsfile

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

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,6 @@ installed, pre-commit will run every time you commit.
7676
Alternatively, if you'd rather not install any hooks, you can simply use
7777
`make test` as usual, which will also run the hooks.
7878

79-
### Troubleshooting: Cracklib Error
80-
81-
If you're trying to run make install-hooks on ocfweb (or related repos) and get
82-
this error:
83-
84-
```
85-
./_cracklib.c:40:10: fatal error: 'crack.h' file not found
86-
#include <crack.h>
87-
^~~~~~~~~
88-
1 error generated.
89-
```
90-
91-
The issue relates to the cracklib package not finding the necessary header files
92-
to install. Make sure cracklib is installed on your machine
93-
(https://github.com/cracklib/cracklib, if you're on Mac,
94-
`brew install cracklib`).
95-
9679
## Deploying changes
9780

9881
Deploying changes involves:

default.nix

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
, poetry-core
99

1010
# system dependencies
11-
, cracklib
1211

1312
# python dependencies
1413
, attrs
@@ -24,21 +23,10 @@
2423
, sqlalchemy_1_4
2524
, dos2unix
2625
, pyasn1
26+
, zxcvbn
2727
}:
2828

2929
let
30-
cracklib-pypi = buildPythonPackage rec {
31-
pname = "cracklib";
32-
version = "2.9.6";
33-
format = "setuptools";
34-
src = fetchPypi {
35-
inherit pname version;
36-
hash = "sha256-o/S6jNIOrppRbridviJJghx3EIsERyMFW0W/eTYVABI=";
37-
};
38-
propagatedBuildInputs = [ cracklib ];
39-
# cracklib uses unittest assertEquals which is removed in Python 3.12
40-
doCheck = false;
41-
};
4230
pysnmp-pypi = buildPythonPackage rec {
4331
pname = "pysnmp";
4432
version = "4.4.12";
@@ -89,19 +77,17 @@ in
8977

9078
buildPythonPackage {
9179
pname = "ocflib";
92-
version = "2025-08-27";
80+
version = "2025-08-28";
9381
format = "pyproject";
9482
disabled = pythonOlder "3.7";
9583
src = ./.;
9684

9785
buildInputs = [
98-
cracklib # cracklib system library
9986
];
10087

10188
propagatedBuildInputs = [
10289
attrs
10390
cached-property-pypi
104-
cracklib-pypi # cracklib python package
10591
dnspython
10692
jinja2
10793
ldap3
@@ -115,6 +101,7 @@ buildPythonPackage {
115101
requests
116102
sqlalchemy_1_4
117103
poetry-core
104+
zxcvbn
118105
];
119106

120107
meta = with lib; {

ocflib/account/validators.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import string
44
import sys
55

6-
import cracklib
6+
from zxcvbn import zxcvbn
77

88
import ocflib.misc.mail
99
import ocflib.account.search as search
@@ -364,16 +364,9 @@ def validate_password(username, password, strength_check=True):
364364
if len(password) < 12:
365365
raise ValueError('Password must be at least 12 characters.')
366366

367-
s = difflib.SequenceMatcher()
368-
s.set_seqs(password, username)
369-
370-
if s.ratio() > 0.6:
371-
raise ValueError('Password is too similar to username.')
372-
373-
try:
374-
cracklib.VeryFascistCheck(password)
375-
except ValueError as e:
376-
raise ValueError('Password problem: {}.'.format(e))
367+
result = zxcvbn(password, user_inputs=[username])
368+
if result['score'] < 4:
369+
raise ValueError('Password is too weak: {}'.format(result['feedback']['warning']))
377370

378371
# sanity check; note we don't use string.whitespace since we don't want
379372
# tabs or newlines

0 commit comments

Comments
 (0)