Refactor minimum password length

This commit is contained in:
amcmanu3 2024-02-19 21:14:15 -05:00
parent bfa0c72412
commit 842e576b5c
4 changed files with 16 additions and 8 deletions

View File

@ -52,7 +52,7 @@ class UsersController:
},
"password": {
"type": "string",
"minLength": 8,
"minLength": self.helper.minimum_password_length,
"examples": ["crafty"],
"title": "Password",
},

View File

@ -77,11 +77,11 @@ class MainPrompt(cmd.Cmd):
# get new password from user
new_pass = getpass.getpass(prompt=f"NEW password for: {username} > ")
# check to make sure it fits our requirements.
if len(new_pass) > 512:
Console.warning("Passwords must be greater than 6char long and under 512")
return False
if len(new_pass) < 6:
Console.warning("Passwords must be greater than 6char long and under 512")
if len(new_pass) < self.helper.minimum_password_length:
Console.warning(
"Passwords must be greater than"
f" {self.helper.minimum_password_length} char long"
)
return False
# grab repeated password input
new_pass_conf = getpass.getpass(prompt="Re-enter your password: > ")

View File

@ -81,6 +81,7 @@ class Helpers:
self.update_available = False
self.ignored_names = ["crafty_managed.txt", "db_stats"]
self.crafty_starting = False
self.minimum_password_length = 8
@staticmethod
def auto_installer_fix(ex):

View File

@ -18,13 +18,20 @@ class DatabaseBuilder:
logger.info("Fresh Install Detected - Creating Default Settings")
Console.info("Fresh Install Detected - Creating Default Settings")
default_data = self.helper.find_default_password()
if password not in default_data:
if "password" not in default_data:
Console.help(
"No default password found. Using password created "
"by Crafty. Find it in app/config/default-creds.txt"
)
username = default_data.get("username", "admin")
password = default_data.get("password", password)
if self.helper.minimum_password_length > default_data.get("password", password):
Console.critical(
"Default password too short"
" using Crafty's created default."
" Find it in app/config/default-creds.txt"
)
else:
password = default_data.get("password", password)
self.users_helper.add_user(
username=username,