| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1766 人关注过本帖
标题:求管理员登陆用md5加密的例子
只看楼主 加入收藏
助人为乐
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2007-3-9
收藏
 问题点数:0 回复次数:7 
求管理员登陆用md5加密的例子

例如我在添加管理员 写到数据库的密码字段是加密的 然后我在登陆的时候 我依然可以登陆 这一加密 和解密的过程我应该怎么写呢 恳请各位给指点一下 :

我写入的代码:这里怎么加密写入:

SqlCommand cmd = new SqlCommand("insert into admin values('" + this.adminname.Text.ToString().Trim() + "','" + this.adminpwd.Text.ToString().Trim() + "',1)", conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Response.Write("<script>alert('添加成功')</script>");




那么我在登陆的时候: 这里要怎么来写呢
protected void Submit1_ServerClick(object sender, EventArgs e)
{

SqlConnection con = DB.condb();
SqlCommand cmd = new SqlCommand("select count(*) from admin where adminname='" + this.adminname.Text.ToString() + "'and adminpwd='" + this.adminpwd.Text.ToString() + "'", con);
try
{
con.Open();
int ln = Convert.ToInt32(cmd.ExecuteScalar().ToString());
con.Close();
if (ln > 0)
{
Session["adminname"] = this.adminname.Text.ToString();
Response.Write("<script language='javascript'>alert('登陆成功!');window.location.href='admin.aspx';</script>");


}
else
{

Response.Write("<script language='javascript'>alert('密码或者用户名字错误,请重新登陆!');window.location.href='login.aspx';</script>");

}

}

catch(SqlException ex)
{
Response.Write(ex);

}
}
}

谢谢朋友们了 !!!向你们学习

搜索更多相关主题的帖子: 管理员 数据库 例子 
2007-10-20 09:21
smoon
Rank: 1
等 级:禁止访问
帖 子:461
专家分:0
注 册:2006-4-29
收藏
得分:0 
public string md5(string str,int code)
{
if(code==16) //16位MD5加密(取32位加密的9~25字符)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5").ToLower().Substring(8,16) ;
}
else//32位加密
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5").ToLower();
}
}

登录的时候因为md5是不可逆的。所以一般是再加密一次然后用加密后的数据和数据库的比较

QQ:860660016
网站:http://
承接各种C#项目中。。。。。
2007-10-20 10:13
助人为乐
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2007-3-9
收藏
得分:0 

真的感谢您 我是初学 还很菜 不知道怎么去实现,希望你在我代码上写一下这个过程 让我有个学习的机会。。

2007-10-20 10:19
助人为乐
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2007-3-9
收藏
得分:0 
回复:(助人为乐)求管理员登陆用md5加密的例子
还是没有搞出来 那位在帮帮忙 谢谢
2007-10-23 08:42
垃圾的沉默
Rank: 1
等 级:新手上路
威 望:2
帖 子:511
专家分:0
注 册:2007-6-25
收藏
得分:0 
加密:
//获取要加密的字段,并转化为Byte[]数组
byte[] data = System.Text.Encoding.Unicode
.GetBytes(source.Text.ToCharArray());
//建立加密服务
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
//加密Byte[]数组
byte[] result = md5.ComputeHash(data);
//将加密后的数组转化为字段
string sResult = System.Text.Encoding.Unicode.GetString(result);
//作为密码方式加密
string EnPswdStr = System.Web.Security.FormsAuthentication.
HashPasswordForStoringInConfigFile(source.Text.ToString(), "MD5");
//显示出来

登陆-
if (this.AdminID.Text != "" && this.source.Text != "")
{
bool pwdword = false;
string serverpwd;
OleDbConnection cnn;
OleDbCommand cmd;
OleDbDataReader datar;
string sql, strcnn;
strcnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/DataBase.mdb");
cnn = new OleDbConnection(strcnn);
cnn.Open();
sql = "select * from userG where userID='" + AdminID.Text + "'";
cmd = new OleDbCommand(sql, cnn);
datar = cmd.ExecuteReader();
if (datar.Read())
{
serverpwd = datar["userPWD"].ToString();
Session["userG"] = datar["userN"].ToString();
byte[] data = System.Text.Encoding.Unicode
.GetBytes(source.Text.Trim().ToCharArray());
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(data);
string sResult = System.Text.Encoding.Unicode.GetString(result);
string EnPswdStr = System.Web.Security.FormsAuthentication.
HashPasswordForStoringInConfigFile(source.Text.ToString(), "MD5");
for (int i = 0; i < EnPswdStr.Length; i++)
{
if (EnPswdStr[i] != serverpwd[i])
{
Response.Write("<script>alert('密码错误!!')" + "</sc" + "rip" + "t>"); ;
break;
}
}
if (this.AdminID.Text == "" && this.source.Text == "")
{
Response.Write("<script>alert('密码或用户名不能为空!!')" + "</sc" + "rip" + "t>");
}
if (EnPswdStr == serverpwd)
{
if (TextBox1.Text != Session["ValidateCode"].ToString())
{
Response.Write("<script>alert('验证码错误,请确认!!')" + "</sc" + "rip" + "t>");
}
else
{
bool a;
a = true;
if (bool.Parse(datar["sc"].ToString()) == a)
{
Session["userN"] = AdminID.Text;
Response.Redirect("user/index.htm");
}
else
{
Session["userN"] = AdminID.Text;
Response.Redirect("admin_index.htm");
}
}
}
else
{
Response.Write("<script>alert('你的输入错误请确认以后再输入!!')" + "</sc" + "rip" + "t>");
}
}
}
}
catch
{
Response.Write("<script>alert('你的输入错误请确认以后再输入!!')" + "</sc" + "rip" + "t>");
}
}

人们笑我太疯癫...我笑人们太正经
2007-10-23 09:16
beblue
Rank: 1
等 级:新手上路
帖 子:182
专家分:0
注 册:2007-3-24
收藏
得分:0 

继续向前-------------------努力成为高手
2007-10-23 10:15
垃圾的沉默
Rank: 1
等 级:新手上路
威 望:2
帖 子:511
专家分:0
注 册:2007-6-25
收藏
得分:0 
加上楼上的那些..是够全面的了..再不行的话是没话说了

人们笑我太疯癫...我笑人们太正经
2007-10-23 11:00
skylence
Rank: 1
等 级:新手上路
帖 子:92
专家分:0
注 册:2006-11-15
收藏
得分:0 

那去试试看 顶........


2007-11-09 22:18
快速回复:求管理员登陆用md5加密的例子
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015112 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved