From 45c7c7de90912060d6db8265e7b1d728f44e9fd4 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Wed, 22 Apr 2009 07:02:28 +0000
Subject: [PATCH] Add core:AdminPassword authentication source.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1469 44740490-163a-0410-bde0-09ae8108e29a
---
 .../core/lib/Auth/Source/AdminPassword.php    | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 modules/core/lib/Auth/Source/AdminPassword.php

diff --git a/modules/core/lib/Auth/Source/AdminPassword.php b/modules/core/lib/Auth/Source/AdminPassword.php
new file mode 100644
index 000000000..69babb9f3
--- /dev/null
+++ b/modules/core/lib/Auth/Source/AdminPassword.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * Authentication source which verifies the password against
+ * the 'auth.adminpassword' configuration option.
+ *
+ * @package simpleSAMLphp
+ * @version $Id$
+ */
+class sspmod_core_Auth_Source_AdminPassword extends sspmod_core_Auth_UserPassBase {
+
+
+	/**
+	 * Constructor for this authentication source.
+	 *
+	 * @param array $info  Information about this authentication source.
+	 * @param array $config  Configuration.
+	 */
+	public function __construct($info, $config) {
+		assert('is_array($info)');
+		assert('is_array($config)');
+
+		/* Call the parent constructor first, as required by the interface. */
+		parent::__construct($info, $config);
+
+		$this->setForcedUsername("admin");
+	}
+
+
+	/**
+	 * Attempt to log in using the given username and password.
+	 *
+	 * On a successful login, this function should return the users attributes. On failure,
+	 * it should throw an exception. If the error was caused by the user entering the wrong
+	 * username or password, a SimpleSAML_Error_Error('WRONGUSERPASS') should be thrown.
+	 *
+	 * Note that both the username and the password are UTF-8 encoded.
+	 *
+	 * @param string $username  The username the user wrote.
+	 * @param string $password  The password the user wrote.
+	 * @return array  Associative array with the users attributes.
+	 */
+	protected function login($username, $password) {
+		assert('is_string($username)');
+		assert('is_string($password)');
+
+		$config = SimpleSAML_Configuration::getInstance();
+		$adminPassword = $config->getString('auth.adminpassword', '123');
+		if ($adminPassword === '123') {
+			/* We require that the user changes the password. */
+			throw new SimpleSAML_Error_Error('NOTSET');
+		}
+
+		if ($username !== "admin") {
+			throw new SimpleSAML_Error_Error('WRONGUSERPASS');
+		}
+
+		if ($password !== $adminPassword) {
+			throw new SimpleSAML_Error_Error('WRONGUSERPASS');
+		}
+
+		return array('user' => array('admin'));
+	}
+
+}
+
+
+?>
\ No newline at end of file
-- 
GitLab