现在想把原来一个网站的数据用户添加到mojoportal2319的数据库表中
涉及到,原来数据库用户加密方式与mojoportal中加密方式不一样,需要修改加密解密代码。
1:修改mojoMembershipProvider.cs中
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
public string EncodePassword(string pass, MembershipPasswordFormat passwordFormat)
{
if (passwordFormat == MembershipPasswordFormat.Clear)
{
return pass;
}
if (passwordFormat == MembershipPasswordFormat.Hashed)
{
return Hash(pass);
}
//byte[] bIn = Encoding.Unicode.GetBytes(pass);
//byte[] bRet = EncryptPassword(bIn);
//return Convert.ToBase64String(bRet);
Byte[] clearBytes = new UnicodeEncoding().GetBytes(pass);
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}
public string UnencodePassword(string pass, MembershipPasswordFormat passwordFormat)
{
switch (passwordFormat)
{
case MembershipPasswordFormat.Clear:
return pass;
case MembershipPasswordFormat.Hashed:
throw new ProviderException("Can't decrypt hashed password");
default:
//byte[] bIn = Convert.FromBase64String(pass);
//byte[] bRet = DecryptPassword(bIn);
//if (bRet == null)
// return null;
//return Encoding.Unicode.GetString(bRet);
Byte[] clearBytes = new UnicodeEncoding().GetBytes(pass);
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
if (hashedBytes == null)
return null;
return BitConverter.ToString(hashedBytes);
}
}
上图中,注释为原代码,注释下为修改的代码。
2 数据库修改代码如下:
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
alter table mp_users
add money int
go
alter table mp_Users
add constraint mp_users_money default(0) for money
go
alter table mp_users
add school nvarchar(200)
go
update users
set email='temp@163.com'
where email='' or email is null
go
insert into mp_users (LoginName,siteID,Name,Money,Email,Password,School,SiteGuid )
select distinct name,1,realname,money,email,password,School,'13CEECCE-C40E-4DDA-9087-7C70249E0E13' from users
where id!=4436
go
delete from mp_users where name='admin' and userID>2