求 用.net做的记住密码 源码 急疯了
求 用.net做的记住密码 源码 急疯了 要对的 --------------------编程问答-------------------- Cookie就可以了啊 --------------------编程问答----------------------------------------编程问答--------------------
/// <summary>
/// 记住密码
/// </summary>
private void RememberPassword()
{
if (cbRememberPW.Checked)
{
//记住密码
System.Web.HttpCookie newCookie = new HttpCookie("user");
newCookie.Values["username"] = tbUserName.Value.Trim();
string strPW = tbPassword.Value.Trim(); //最好加密后的密码放到COOKIE内
newCookie.Values["password"] = strPW;
newCookie.Expires = DateTime.Now.AddDays(15);
Response.AppendCookie(newCookie);
}
else
{
System.Web.HttpCookie cookie = Request.Cookies["user"];
if (cookie != null)
{
cookie.Expires = DateTime.Now.AddDays(-2);
Response.Cookies.Set(cookie);
}
}
}
--------------------编程问答-------------------- cookie,session --------------------编程问答-------------------- cookie就行了吧,就多加个设置过期日期嘛 --------------------编程问答--------------------
//在页面加载时 调用此方法
/// <summary>
/// 读取cookie中的密码
/// </summary>
private void ReadPassword()
{
if (Request.Cookies["user"] != null)
{
string strPassword = Request.Cookies["user"]["password"].ToString();
tbUserName.Value = Request.Cookies["user"]["username"].ToString();
cbRememberPW.Checked = true;
}
}
使用cookie网上有很多列子的 --------------------编程问答-------------------- 有没有前后台代码的 --------------------编程问答--------------------
后台代码如上
还有直接前台JavaScript实现:
<script type="text/javascript">
window.onload = function() {
var strCookies = document.cookie;
if (strCookies.indexOf("userAccount") >= 0) {
var strC = strCookies.split(";");
if (strC.length > 0) {
for (i = 0; i < strC.length; i++) {
if (strC[i].indexOf("userAccount=") >= 0) {
document.getElementById("userUid").value = strC[i].replace("userAccount=", "");
document.getElementById("Rmp").checked = true;
}
if (strC[i].indexOf("userAccountPsw=") >= 0) {
document.getElementById("Password").value = strC[i].replace("userAccountPsw=", "");
}
}
}
}
}
function SetCookies() {
if (document.getElementById("Rmp").checked) {
var exp = new Date();
exp.setDate(exp.getDate()+3650);
document.cookie = "userAccount=" + document.getElementById("userUid").value+ "; expires=" + exp.toGMTString();
document.cookie = "userAccountPsw=" + document.getElementById("Password").value+ "; expires=" + exp.toGMTString();
} else {
Deletecookie("userAccount");
Deletecookie("userAccountPsw");
}
}
function Setcookie (name, value) { //设置名称为name,值为value的Cookie
var argc = SetCookie.arguments.length;
var argv = SetCookie.arguments;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + value +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function Deletecookie (name) { //删除名称为name的Cookie
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function getCookieVal(offset) { //取得项名称为offset的cookie值
var endstr = document.cookie.indexOf(";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) { //取得名称为name的cookie值
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
</script> --------------------编程问答--------------------
+1
补充:.NET技术 , ASP.NET