<?
	#---------------------------------------------------------------------#
	# This source code is (c)2000 White Pajamas, Inc                      #
	# see http://www.stonekeep.com/license.html for licensing information #
	#---------------------------------------------------------------------#

	#--------------------------------------------------------------------
	# $Id: changepw.php3,v 1.10 2000/12/14 19:13:45 shevett Exp $
	#--------------------------------------------------------------------
	
	#
	# Change a  password on a user.
	#
	# $curruser should have the default user.
	#

	if ($f_func == "changepw") { ?>
	
	<tr><td>&nbsp</td></tr>
	<tr bgcolor=#BBBBBB>
	<td width=100% bgcolor=#202020 align=center>
	<table bgcolor=#bbbbbb cellspacing=2>
		<tr>
			<td bgcolor=#909090 align=center>
				<h3>Change Password
			</td>
		</tr>
		<tr>
			<td bgcolor=#909090 align=center>
				Note that changing a users password <br>
				will log them out of Keystone <br>
				immediately.
			</td>
		</tr>
		<tr>
			<td bgcolor=#909090 align=left>
				<form method="post" action="nbrowse.php3">
				<?
					if (Member("$curruser","admin")) {
						echo "<i>Username</i><br>";
						# FIXME: needs maxsize based on database query
						echo "<input type=text name=_username size=20 value=\"$curruser\">";
						echo "<br>";
					} else {
						echo "<input type=hidden name=_username value=\"$curruser\">";
					}
				?>
				<input type=hidden name="f_process" value="changepw">
				<i>New Password</i><br>
				<!-- FIXME: needs maxsize based on database query -->
				<input type=password name="_npwd1" size=20><br>
				<i>Retype New Password</i><br>
				<!-- FIXME: needs maxsize based on database query -->
				<input type=password name="_npwd2" size=20>
				<hr><center>
				<input type=submit value="Post">
			</td>
		</tr>
	</table>
	</td>
	</tr>
	
	<?
	
	} else {
	
		if ($f_process == "changepw") {
			if ("$_npwd1" <> "$_npwd2") {
				$lastresult[0]=1;
				$lastresult[1]="Password change FAILED (passwords do not match)";
			} else {
				$pwdmd5 = md5("$_npwd1");
				$result=db_query("update people set passwd='$pwdmd5' where login='$_username'");
				$count=db_affected_rows($result);
				if ($count > 0) {
					$lastresult[0]=0;
					$lastresult[1]="Password change for '$_username' successful.";
				} else {
					$lastresult[0]=1;
					$lastresult[1]="Password change FAILED.";
				}
			}
		} else {

			#
			# We shouldn't have gotten here.
			#
			
			$lastresult[0]=1;
			$lastresult[1]="Unexpected condition occured! [changepw.php3]";
		}
	}
	
	?>
