📄 adminpwd.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
//该源码下载自www.51aspx.com(51aspx.com)
namespace examonline
{
/// <summary>
/// adminpwd 的摘要说明。
/// </summary>
public partial class adminpwd : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if((bool)Session["IsLogined"]==false)
{
Response.Redirect("index.aspx");
}
lblmsg.Text=(string)Session["info"];
Session["info"]="";
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void btnlogin_Click(object sender, System.EventArgs e)
{
string oldpwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtOldpwd.Text, "MD5");
string newpwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtNewpwd.Text, "MD5");
string repwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtRepwd.Text, "MD5");
if(newpwd!=repwd)
{
Session["info"]="密码确认有误!";
Response.Redirect("adminpwd.aspx");
Response.End();
}
string sql = "update [admin] set password='"+newpwd+"' where username='" + txtid.Text.Trim() + "' and password='" + oldpwd + "'";
SqlConnection cn = new SqlConnection("server=(local);uid=sa;pwd=51aspx;database=examonline");
SqlCommand cmd = new SqlCommand(sql, cn);
try
{
cn.Open();
int h = cmd.ExecuteNonQuery();
if(h>0)
{
lblmsg.Text="修改成功!";
}
else
{
Session["info"] = "用户名或密码错误!";
Response.Redirect("adminpwd.aspx");
Response.End();
}
}
catch(SqlException ex)
{
Session["info"] = "数据库错误:" + ex.Message.ToString();
Response.Redirect("adminpwd.aspx");
Response.End();
}
finally
{
cn.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -