我有登录页面,用户输入他们的电子邮件和密码,但是当他们输入错误的密码时,我想显示警报或文本,例如(您输入的密码无效)。我已经检查Checkpass不为空做一些事情,否则我不知道我应该做什么老实说。任何人都可以帮助我或指出我正确的方向!
提前致谢:)
控制器:
[HttpPost]
public JsonResult Login(string Mail, string pass)
{
var hashedPass = PasswordSecurity.PasswordStorage.CreateHash(pass);
using (DbNameSpace db = new DbNameSpace())
{
var query = from cbr in db.Contact_Business_Relation
join c in db.Contact on cbr.Contact_No_ equals c.Company_No_
join sa in db.Sales_Header on cbr.No_ equals sa.Sell_to_Customer_No_
join px in db.PX2 on c.E_Mail equals px.Email_ID
where c.E_Mail == Mail.ToLower()
select new
{
Mail = c.E_Mail,
pass = px.PS,
};
var user = query.FirstOrDefault();
var CheckPass = PasswordSecurity.PasswordStorage.VerifyPassword(pass, user.pass);
if (user != null && CheckPass) //Checkpassword
{
Session["Email"] = user.Mail.ToString();
}
else {
// ??
}
return Json(user, JsonRequestBehavior.AllowGet);
}
}
JavaScript:
<script>
$(document).ready(function () {
$("#login").click(function (e) {
var email = $("input[name=Mail]").val();
var password = $("input[name=pass]").val();
e.preventDefault();
$.ajax({
type: "POST",
dataType: "json",
url: '@Url.Action("Login", "Account")',
data: { Mail: email, pass: password },
success: function (status) {
if (status) {
window.location.href = "/Account/Index";
}
}
});
});
});
</script>
江户川乱折腾
Smart猫小萌
慕丝7291255
相关分类