protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e )
{
TextBox 输入新密码TextBox = (TextBox)e.Item.FindControl("输入新密码TextBox"); //传选择行的控件值
string NewPassword = 输入新密码TextBox.Text.Trim(); //接收输入的新密码值
if (!string.IsNullOrEmpty(NewPassword))
{
GoldenSeaDataDataContext context = new GoldenSeaDataDataContext();
TextBox 人员编号TextBox = (TextBox)e.Item.FindControl("人员编号TextBox");
string pwdsalt = (from u in context.aspnet_Memberships where u.人员编号 == 人员编号TextBox.Text select u.PasswordSalt).First().ToString(); //找对应的PasswordSalt
//string userid = (from u in context.aspnet_Memberships where u.人员编号 == 人员编号TextBox.Text select u.UserId).First().ToString(); //找对应的UserId
//string username = (from u in context.aspnet_Users where u.UserId.ToString() == userid select u.UserName).First().ToString(); //找对应的UserName
// System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser(username);
string NewPwd = CreatePasswordHash(NewPassword, pwdsalt);
//更新数据库
aspnet_Membership aspnet_Memberships = context.aspnet_Memberships.First(c => c.人员编号 == 人员编号TextBox.Text);
aspnet_Memberships.Password = NewPwd;
aspnet_Memberships.IsLockedOut = false;
context.SubmitChanges();
}
}
public string CreatePasswordHash(string Password, string Salt)
{
string passwordFormat = string.Empty;
if (String.IsNullOrEmpty(passwordFormat))
passwordFormat = "SHA1";
byte[] bytes = Encoding.Unicode.GetBytes(Password);
byte[] src = Convert.FromBase64String(Salt);
byte[] dst = new byte[src.Length + bytes.Length];
byte[] inArray = null;
System.Buffer.BlockCopy(src, 0, dst, 0, src.Length);
System.Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
HashAlgorithm algorithm = HashAlgorithm.Create(passwordFormat);
inArray = algorithm.ComputeHash(dst);
return Convert.ToBase64String(inArray);
}