系统管理员修改密码

 

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);
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值