C# 中登录界面 中的 “记住密码” 代码怎么实现???
想在 登陆界面 加一个记住密码......
2011-10-11 08:17
2011-10-11 10:46
2011-10-11 15:13
2011-10-11 16:04
2011-10-11 16:39
2011-10-13 10:47
2011-10-13 10:47
2011-10-13 13:42
程序代码: public static string StrEncrypt(string str, int key)
{
int max = (int)char.MaxValue;
int j = str.Length;
string rtn = "";
for (int i = 0; i < j; i++)
{
long x = (int)str[i];
if (i % 2 == 0)
{
x = x + i / 2 + 2 * j + key;
}
else
{
x = x + 2 * i + j / 2 - key;
}
x = x % max;
rtn += (char)x;
}
return rtn;
}
public static string StrDecrypt(string str, int key)
{
int max = (int)char.MaxValue;
int j = str.Length;
string rtn = "";
for (int i = 0; i < j; i++)
{
long x = (int)str[i];
if (i % 2 == 0)
{
x = x - i / 2 - j * 2 - key;
}
else
{
x = x - i * 2 - j / 2 + key;
}
while (x < 0)
{
x += max;
}
rtn += (char)x;
}
return rtn;
}
程序代码: public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string ls = "{admin|0}{test|123}";
string inf = "";
UserPwdMgr upm = new UserPwdMgr(ls);
inf += "\nContain admin:" + upm.Contain("admin").ToString();
inf += "\nContain abc:" + upm.Contain("abc").ToString();
inf += "\nadmin'pwd:" + upm.GetPwd("admin");
inf += "\nabc'pwd:" + upm.GetPwd("abc");
inf += "\ncur:" + upm.ToString();
upm.Add("adder", "456");
inf += "\nadd adder 456:" + upm.ToString();
upm.Remove("test");
inf += "\nremove test:" + upm.ToString();
MessageBox.Show(inf);
ls = upm.ToString();
//这个ls 你随便存个地方就行了 settings文件里 或者 数据库里 或者 你自己定义个文件
}
}
public class UserPwd
{
public string usr = "";
public string pwd = "";
public UserPwd(string u, string p)
{
usr = u;
pwd = p;
}
public override string ToString()
{
return "{" + usr + "|" + pwd + "}";
}
}
public class UserPwdMgr
{
public List<UserPwd> upList = new List<UserPwd>();
public UserPwdMgr(string list)
{
string[] ary = list.Split(new char[] { '{', '|', '}' }, StringSplitOptions.RemoveEmptyEntries );
if (ary.Length % 2 != 0)return;
for (int i = 0; i < ary.Length; i += 2)
{
upList.Add(new UserPwd(ary[i], ary[i + 1]));
}
}
public UserPwd Search(string usr)
{
for (int i = 0; i < upList.Count; i++)
{
if (upList[i].usr == usr) return upList[i];
}
return null;
}
public bool Contain(string usr)
{
return Search(usr) != null;
}
public void Add(string usr, string pwd)
{
UserPwd up = Search(usr);
if (up == null)
{
upList.Add(new UserPwd(usr, pwd));
}
else
{
up.pwd = pwd;
}
}
public void Remove(string usr)
{
UserPwd up = Search(usr);
if (up != null)
{
upList.Remove(up);
}
}
public string GetPwd(string usr)
{
UserPwd up = Search(usr);
if (up == null) return "不存在该用户";
else return up.pwd;
}
public override string ToString()
{
string ls = "";
for (int i = 0; i < upList.Count; i++) ls += upList[i].ToString();
return ls;
}
}
2011-10-13 14:16
2011-10-15 18:33