我想更新登录密码
当用户登录然后看到他们自己的个人资料后,我在我的应用程序中做什么
学生.cs
namespace Demo.Models
{
public class student
{
public int studentid { get; set; }
[Display(Name = "FirstName")]
public string firstname { get; set; }
[Display(Name = "LastName")]
public string lastname { get; set; }
[Display(Name = "UserName")]
public string username { get; set; }
[Display(Name = "Password")]
public string password { get; set; }
[Display(Name = "Emailid")]
public string emailid { get; set; }
}
家庭控制器.cs
public ActionResult Index()
{
if (Session["username"] == null)
{
return RedirectToAction("Login", "Home");
}
else
{
return View(getcurrentstudent());
}
}
public student getcurrentstudent()
{
var currentusername = Session["username"].ToString();
var currentpassword = Session["password"].ToString();
var currentstu = _dbcontextstud.stud.Where(s => s.username == currentusername && s.password == currentpassword).SingleOrDefault();
return currentstu;
}
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(student stud)
{
var login = _dbcontextstud.stud.Where(x => x.username == stud.username && x.password == stud.password).FirstOrDefault();
if (login != null)
{
Session["username"] = login.username.ToString();
Session["password"] = login.password.ToString();
return RedirectToAction("Index");
}
return RedirectToAction("Login");
}
public ActionResult create()
{
return View();
}
[HttpPost]
public ActionResult create(student stud)
{
var create = _dbcontextstud.stud.Add(stud);
_dbcontextstud.SaveChanges();
return RedirectToAction("Login");
}
索引.cshtml
@model Demo.Models.student
<h2>Index</h2>
@if (Session["username"] != null)
{
<text>Welcome <strong>@Session["username"].ToString()</strong></text>
}
<p>
@Html.ActionLink("Logout", "Logout")
</p>
<table class="table">
<tr>
<td>
@Html.DisplayFor(model => model.firstname)
</td>
<td>
@Html.DisplayFor(model => model.lastname)
</td>
<td>
@Html.DisplayFor(model => model.username)
</td>
<td>
@Html.DisplayFor(model => model.password)
</td>
<td>
@Html.DisplayFor(model => model.emailid)
</td>
</tr>
</table>
数据库图:
登录时查看参考:
如何在 MVC 中更新登录密码或哪些字段额外需要添加表来更新密码或更新密码的逻辑实现?
请帮忙

