<!--
whilvydy 新闻发布系统
-->

<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%@ include file = "func/parameter.jsp" %>
<%@ page import="java.io.*" %> 
<%@ page import="java.util.*" %>
<jsp:useBean id="password" scope="page" class="net.jspcn.db.DbConnect" />
<jsp:useBean id='oMD5' scope='page' class='net.jspcn.tool.MD5'/>
<jsp:useBean id='StrTool' scope='page' class='net.jspcn.tool.StringProcess'/>

<%
int user_power = Integer.parseInt((String) session.getValue("user_power"));
if (user_power<1)
response.sendRedirect("login.jsp");

String sql;
ResultSet rs;

String user_password_old = request.getParameter("user_password_old");
String user_password_new = request.getParameter("user_password_new");
String user_password_new1 = request.getParameter("user_password_new1");


if(user_password_new!=null && user_password_new1!=null&&user_password_old!=null)
{

	if(user_password_new.equals(user_password_new1)&&user_password_new.length()>=6)
	{
	user_password_new = oMD5.getMD5ofStr(user_password_new);
	user_password_old = oMD5.getMD5ofStr(user_password_old);
	password.openConnection();
	sql = "select count(*) as user_num from "+user_table+" where user_id="+session.getValue("user_id")+" and user_password='"+user_password_old+"'";
	rs = password.executeQuery(sql);
	rs.next();
	
		if(Integer.parseInt(rs.getString("user_num"))==1)
		{
			sql = "update "+user_table+" set user_password = '"+user_password_new+"' where user_id ="+session.getValue("user_id");
			password.executeQuery(sql);	
			
			String sql_in = "insert into "+logrecord_table+" (logrecord_id,user_name,operation_time,logrecord_operation) values('','"+session.getValue("user_name")+"',now(),'user change password successful')";
			password.executeUpdate(sql_in);			      
			%>
			<script language=vbscript>
			 	msgbox "操作成功!您的密码已经修改"
		        </script>
		         <%
		}
		else {
		%>您的原密码好象不对耶！
		<%	
			String sql_in = "insert into "+logrecord_table+" (logrecord_id,user_name,operation_time,logrecord_operation) values('','"+session.getValue("user_name")+"',now(),'user change password failed for old password is wrong')";
			password.executeUpdate(sql_in);			
		}
	}
	else { %>
	您两次输入的密码不相同!<br>或你的新密码太短
	<%
	}
}

%>


<%@ include file = "func/header.jsp" %>
<body>
<div align=center>

更改密码

<form action="password_man.jsp" method=post name=form1 onsubmit="return formCheck()">
    <table width="50%"  border="1" cellspacing="0" cellpadding="2"  bordercolor="#00CC66"  borderColorDark="#FFFFFF" borderColorLight="#00CC66">
	<tr> 
        	<td><div align="right">输入旧密码</div></td>
        	<td><div align="left"><input name="user_password_old" type="password"  class=input size="12" maxlength=20></div></td>
	</tr>
	<tr> 
        	<td><div align="right">输入新密码</div></td>
        	<td><div align="left"><input name="user_password_new" type="password"  class=input size="12" maxlength=20>&nbsp;</div></td>
	</tr>
	<tr> 
        	<td><div align="right">确认新密码</div></td>
        	<td><div align="left"><input name="user_password_new1" type="password"  class=input size="12" maxlength=20></div></td>
	</tr>
  </table>
  <br>
  <input type=submit value="确 定" class=button>&nbsp;&nbsp;&nbsp;&nbsp;<input type=reset value="重 置" class=button>
 </div>
</form>

<SCRIPT language=JavaScript>
         function formCheck()
	{
		if(document.form1.user_password_old.value=="")
            	{
            		alert("请输入您的旧密码!");
			document.form1.user_password_old.focus();
			return false;
		}     
		
		if(document.form1.user_password_new.value=="")
		{
			alert("请输入您的新密码!");
			document.form1.user_password_new.focus();
			return false;
		}
		
		if(document.form1.user_password_new1.value!=document.form1.user_password_new.value)
		{
			alert("您两次输入的密码不同，请重新输入!");
			document.form1.user_password_new1.focus();
			return false;
		}
		
         }
</SCRIPT>

<%@ include file = "func/footer.jsp" %>