luci-base: add helper functions for password
authorChristian Korber <redacted>
Mon, 1 Jun 2026 06:29:55 +0000 (08:29 +0200)
committerPaul Donald <redacted>
Wed, 3 Jun 2026 10:49:07 +0000 (13:49 +0300)
Because validating password is used in `luci-app-acl` and
`luci-mod-system` this commit adds helper functions for them to
luci-base.

Signed-off-by: Christian Korber <redacted>
modules/luci-base/htdocs/luci-static/resources/tools/password.js [new file with mode: 0644]

diff --git a/modules/luci-base/htdocs/luci-static/resources/tools/password.js b/modules/luci-base/htdocs/luci-static/resources/tools/password.js
new file mode 100644 (file)
index 0000000..64b451c
--- /dev/null
@@ -0,0 +1,32 @@
+'use strict';
+
+'require baseclass';
+'require uci';
+
+return baseclass.extend({
+       checkLength(p, required) {
+               let enough = p.length >= parseInt(required);
+
+               if (required && !enough)
+                       return false;
+
+               return true;
+       },
+
+       checkDigits(p) {
+               let m = p.match(/\d/);
+
+               return m ? true : false;
+       },
+
+       checkUpperLower(p) {
+
+               return /[a-z]/.test(p) && /[A-Z]/.test(p);
+       },
+
+       checkSpecialChars(p) {
+               let m = p.match(/[^a-zA-Z0-9]/);
+
+               return m ? true : false;
+       }
+});
git clone https://git.99rst.org/PROJECT