密码不应更改,因此请检查我的代码 [英] password should not change so please chaeck my code

查看:81
本文介绍了密码不应更改,因此请检查我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[HttpPost]
public ActionResult ChangePassword1(FormCollection fc, string id)
{
    DataClasses1DataContext dcdc = new DataClasses1DataContext();
    UpdatePassword up = new UpdatePassword();
    User_Master reg1 = (from var in dcdc.User_Masters
                     where var.Name == Session["FirstName"].ToString()
                     select var).FirstOrDefault();
    string OldPassword = fc["OldPassword"];
    if (dcdc.GetTable<user_master>().Where(x => x.Password == OldPassword).Count() == 1)
    {
        if (reg1 != null)
        {
            reg1.Password = fc["NewPassword"];
            dcdc.SubmitChanges();
            return RedirectToAction("Index", "Home");
        }
    }
    else
    {
        return RedirectToAction("ChangePassword1", "Account");
        ViewData["Message"] = "UserName / Password Not Valid";
    }
    return View(up);

}

推荐答案

报价:

if(dcdc.GetTable< user_master>().其中​​(x => x.Password == OldPassword).Count()== 1)

if (dcdc.GetTable<user_master>().Where(x => x.Password == OldPassword).Count() == 1)


在这里,您正在检查数据库中的相似密码.可能有n个用户将使用相同的密码,那么在这种情况下您会怎么做?如果更改密码,则应同时使用当前的用户名和密码.
试试这个:


Here you are checking for the similar passwords in your database. There may be n number of users will be using same password, then at that case what you''ll do? You should check with current username and password both in the case of changing the password.
Try this:

if (dcdc.GetTable<user_master>().Where(x => x.Password == OldPassword && x.UserName == UserName).Count() == 1)
{
   //change the password here
}
else
{
   //Provided old password is not correct.
}
</user_master>



祝一切顺利.
--Amit



All the best.
--Amit


这篇关于密码不应更改,因此请检查我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆