日期:2014-05-18 浏览次数:20598 次
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
static public string PasswordEncrypt(string origPassword)
{
string stemp;
int i;
int l;
int x;
int y;
Random rand = new Random(DateTime.Now.Hour * DateTime.Now.Minute * DateTime.Now.Second);
stemp = origPassword.Trim();
l = stemp.Length;
if (l > 15 || l == 0)
{
return stemp;
}
else
{
string returnV = null;
returnV = Convert.ToChar(l + 100).ToString();
for (i = 2; i <= 16 - l; i++)
{
returnV += Convert.ToChar(Convert.ToInt32(Math.Truncate((double)(24 * rand.NextDouble()))) + 98);
}
for (i = 17 - l; i <= 16; i++)
{
//注意Substring的索引是从0开始,而asp是从1开始
x = Convert.ToInt32(Convert.ToChar(stemp.Substring(i + l - 17, 1)));
if ((x >= 48 && x <= 57) || (x >= 113 && x <= 122))
{
y = 170 - x;
}
else if ((x >= 65 && x <= 80) || (x >= 97 && x <= 112))
{
y = 177 - x;
}
else
{
y = 171 - x;
}
returnV += Convert.ToChar(y);
}
return returnV;
}
}
static public string passwordDeEncrypt(string XPassword)
{
string passwordDeEncrypt = "";
int L = XPassword.Length;
int X, Y;
if (L != 16)
{
return XPassword;
}
else
{
L = (int)XPassword[0] - 100;
for (int I = (16 - L + 1); I < 17; I++)
{
X = (int)XPassword[I - 1];
if ((X >= 48 && X <= 57) || (X >= 113 && X <= 122))
{
Y = 170 - X;
}
else if ((X >= 65 && X <= 80) || (X >= 97 && X <= 112))
{
Y = 177 - X;
}
else
{
Y = 171 - X;
}
passwordDeEncrypt = passwordDeEncrypt + ((char)Y).ToString();
}
}
return passwordDeEncrypt;
}
protected void Button1_Click(object se