From 5d42af9df993cc4c1aa4ef7971eef141221605cf Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 24 Sep 2015 20:42:09 +0200 Subject: [PATCH] (auth) add local database authenticator to library --- .../mvc/app/library/OPNsense/Auth/Local.php | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/opnsense/mvc/app/library/OPNsense/Auth/Local.php diff --git a/src/opnsense/mvc/app/library/OPNsense/Auth/Local.php b/src/opnsense/mvc/app/library/OPNsense/Auth/Local.php new file mode 100644 index 000000000..68ea95d40 --- /dev/null +++ b/src/opnsense/mvc/app/library/OPNsense/Auth/Local.php @@ -0,0 +1,87 @@ +object(); + $userObject = null; + foreach ($configObj->system->children() as $key => $value) { + if ($key == 'user' && !empty($value->name) && (string)$value->name == $username) { + // user found, stop search + $userObject = $value; + break; + } + } + + if ($userObject != null) { + if (isset($userObject->disabled)) { + // disabled user + return false; + } + if (!empty($userObject->expires) + && strtotime("-1 day") > strtotime(date("m/d/Y", strtotime((string)$userObject->expires)))) { + // expired user + return false; + } + $passwd = crypt($password, (string)$userObject->password); + if ($passwd == (string)$userObject->password) { + // password ok, return successfully authen + return true; + } + } + + return false; + } +}