2010-02-28 13:04:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function authenticate($username,$password)
|
|
|
|
{
|
2011-03-19 20:23:23 +00:00
|
|
|
$encrypted_old = md5($password);
|
2011-05-12 22:14:56 +00:00
|
|
|
$row = dbFetchRow("SELECT username,password FROM `users` WHERE `username`= ?", array($username));
|
2011-03-16 18:28:52 +00:00
|
|
|
if ($row['username'] && $row['username'] == $username)
|
2010-02-28 13:04:07 +00:00
|
|
|
{
|
2011-03-19 20:23:23 +00:00
|
|
|
// Migrate from old, unhashed password
|
|
|
|
if ($row['password'] == $encrypted_old)
|
|
|
|
{
|
2011-05-12 22:14:56 +00:00
|
|
|
$row = dbFetchRow("DESCRIBE users password");
|
2011-03-20 21:13:59 +00:00
|
|
|
if ($row['Type'] == 'varchar(34)')
|
|
|
|
{
|
|
|
|
changepassword($username,$password);
|
|
|
|
}
|
2011-03-19 20:23:23 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ($row['password'] == crypt($password,$row['password']))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2010-02-28 13:04:07 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-05 14:54:12 +00:00
|
|
|
function passwordscanchange($username="")
|
2010-03-06 00:00:05 +00:00
|
|
|
{
|
2011-05-05 14:54:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* By default allow the password to be modified, unless the existing
|
|
|
|
* user is explicitly prohibited to do so.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (empty($username) || !user_exists($username)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
2011-05-12 22:14:56 +00:00
|
|
|
return dbFetchCell("SELECT can_modify_passwd FROM users WHERE username = ?", array($username));
|
2011-05-05 14:54:12 +00:00
|
|
|
}
|
2010-03-06 00:00:05 +00:00
|
|
|
}
|
|
|
|
|
2011-03-19 20:23:23 +00:00
|
|
|
/**
|
|
|
|
* From: http://code.activestate.com/recipes/576894-generate-a-salt/
|
|
|
|
* This function generates a password salt as a string of x (default = 15) characters
|
|
|
|
* ranging from a-zA-Z0-9.
|
|
|
|
* @param $max integer The number of characters in the string
|
|
|
|
* @author AfroSoft <scripts@afrosoft.co.cc>
|
|
|
|
*/
|
|
|
|
function generateSalt($max = 15)
|
|
|
|
{
|
|
|
|
$characterList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
|
$i = 0;
|
|
|
|
$salt = "";
|
|
|
|
do
|
|
|
|
{
|
|
|
|
$salt .= $characterList{mt_rand(0,strlen($characterList))};
|
|
|
|
$i++;
|
|
|
|
} while ($i <= $max);
|
|
|
|
|
|
|
|
return $salt;
|
|
|
|
}
|
|
|
|
|
2010-06-21 15:39:43 +00:00
|
|
|
function changepassword($username,$password)
|
2010-03-06 00:00:05 +00:00
|
|
|
{
|
2011-03-19 20:23:23 +00:00
|
|
|
$encrypted = crypt($password,'$1$' . generateSalt(8).'$');
|
2011-05-12 22:14:56 +00:00
|
|
|
return dbUpdate(array('password' => $encrypted), 'users', '`username` = ?', array($username));
|
2010-03-06 00:00:05 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 01:10:05 +00:00
|
|
|
function auth_usermanagement()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2011-03-12 08:50:47 +00:00
|
|
|
|
2011-05-05 14:54:12 +00:00
|
|
|
function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd='1')
|
2010-03-06 01:10:05 +00:00
|
|
|
{
|
2011-03-18 16:56:02 +00:00
|
|
|
if (!user_exists($username))
|
|
|
|
{
|
2011-03-19 20:23:23 +00:00
|
|
|
$encrypted = crypt($password,'$1$' . generateSalt(8).'$');
|
2011-05-12 22:14:56 +00:00
|
|
|
return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd), 'users');
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
2011-03-18 16:56:02 +00:00
|
|
|
}
|
2010-03-06 01:10:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function user_exists($username)
|
|
|
|
{
|
2011-05-12 22:14:56 +00:00
|
|
|
return @dbFetchCell("SELECT * FROM users WHERE username = ?", array($username));
|
2010-03-06 01:10:05 +00:00
|
|
|
}
|
2011-03-12 08:50:47 +00:00
|
|
|
|
2010-03-06 01:15:52 +00:00
|
|
|
function get_userlevel($username)
|
|
|
|
{
|
2011-05-12 22:14:56 +00:00
|
|
|
return dbFetchRow("SELECT `level` FROM `users` WHERE `username` = ?", array($username));
|
2010-03-06 01:15:52 +00:00
|
|
|
}
|
2011-03-12 08:50:47 +00:00
|
|
|
|
2010-03-06 01:22:09 +00:00
|
|
|
function get_userid($username)
|
|
|
|
{
|
2011-05-12 22:14:56 +00:00
|
|
|
return dbFetchRow("SELECT `user_id` FROM `users` WHERE `username` = ?", array($username));
|
2010-03-06 01:22:09 +00:00
|
|
|
}
|
2011-03-12 08:50:47 +00:00
|
|
|
|
2011-03-28 10:48:43 +00:00
|
|
|
function deluser($username)
|
|
|
|
{
|
2011-05-12 22:14:56 +00:00
|
|
|
return dbDelete('users', "`username` = ?", array($username));
|
2011-03-28 10:48:43 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 15:39:43 +00:00
|
|
|
?>
|