From bf0f0b6afe5dd9cd89c8ab02ad7a2365502a3c86 Mon Sep 17 00:00:00 2001
From: Henry Gross-Hellsen <6283258+cowpod@users.noreply.github.com>
Date: Sun, 10 Nov 2024 03:17:16 -0800
Subject: [PATCH] minimum password requirements
---
configure.php | 57 +++++++++++++++++++++++++++++-------
functions/chpw.php | 24 +++++++++++++++
index.php | 4 +--
resources/js/page_account.js | 20 +++++++++++--
resources/js/page_admin.js | 29 ++++++++++++++----
5 files changed, 114 insertions(+), 20 deletions(-)
diff --git a/configure.php b/configure.php
index 83ba21a..9bd3176 100644
--- a/configure.php
+++ b/configure.php
@@ -316,17 +316,25 @@
-
+
diff --git a/functions/chpw.php b/functions/chpw.php
index e68f719..18a8264 100644
--- a/functions/chpw.php
+++ b/functions/chpw.php
@@ -16,6 +16,26 @@
$pass = password_hash($_POST['pass'], PASSWORD_DEFAULT);
}
+function isStrongPassword($password) {
+ if (strlen($password) < 8) {
+ return false;
+ }
+ if (!preg_match('/[a-z]/', $password)) {
+ return false;
+ }
+ if (!preg_match('/[A-Z]/', $password)) {
+ return false;
+ }
+ if (!preg_match('/[0-9]/', $password)) {
+ return false;
+ }
+
+ if (!preg_match('/[\W_]/', $password)) {
+ return false;
+ }
+ return true;
+}
+
global $db;
require_once("db.php");
if (!isset($db)){
@@ -23,6 +43,10 @@
$db->connect();
}
+if (!isStrongPassword($_POST['pass'])) {
+ die("Bad password.");
+}
+
$sql = $db->execute("UPDATE `users` SET `pass` = '".$pass."' WHERE `name` = '".$_SESSION['user']."'"
);
echo $db->error();
diff --git a/index.php b/index.php
index c74f2d7..5c1e2dc 100644
--- a/index.php
+++ b/index.php
@@ -2394,7 +2394,7 @@ class="btn btn-primary">Edit