Coverage for cc_modules/cc_password.py: 29%
7 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-15 14:23 +0100
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-15 14:23 +0100
1"""
2camcops_server/cc_modules/cc_password.py
4===============================================================================
6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CamCOPS.
11 CamCOPS is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 CamCOPS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
26**Password-related functions.**
28"""
30from camcops_server.cc_modules.cc_baseconstants import (
31 PROHIBITED_PASSWORDS_FILE,
32)
35def password_prohibited(password: str) -> bool:
36 """
37 Checks a (cleartext) password and decides if it is prohibited by virtue
38 of being in the UK National Cyber Security Centre (NCSC) list of common,
39 hacked passwords
40 (https://www.ncsc.gov.uk/blog-post/passwords-passwords-everywhere) --
41 ultimately from https://haveibeenpwned.com/.
43 Speed is not critical; we don't cache the file, for example.
44 """
45 with open(PROHIBITED_PASSWORDS_FILE) as f:
46 for line in f:
47 # It doesn't matter if we check against the comment lines.
48 if password == line.rstrip(): # remove trailing newline etc.
49 return True
50 return False