I am trying to get a login form to work using the below method. I am using JQuery version 1.11.2 and MVC4. It appears that the problem is coming from this line of code
<input type="button" onclick="getPasswordHash('password', 'nonce', 'hash');
$('#loginForm').submit(function (event) {
event.preventDefault();
alert('Submitting form.. Please wait');
return true;
})" value = "Login" />
This is the full code which is found in Login.cshtml
@model string
@{
ViewBag.Title = "Login";
}
@section ExtraHeaders
{
<script src="@Url.Content("~/Scripts/Login.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/sha256.js")" type="text/javascript"></script>
}
<form action="@Href("~/Accounts/Login")" method="post" id="loginForm">
<input type="text" name="name" id="name"/> Name <br/>
<input type="password" name="password" id="password"/> Password <br/>
<input type="hidden" name="nonce" id="nonce" value="@Model"/>
<input type="hidden" name="hash" id="hash" value="hash"/>
<input type="button" onclick="getPasswordHash('password', 'nonce', 'hash');
$('#loginForm').submit()" value = "Login" />
</form>
The getPassword method is found in the Login.js file
function getPasswordHash(passwordElement, nonceElement, hashElement)
{
var password = $('#' + passwordElement).attr('value');
var nonce = $('#' + nonceElement).attr('value');
$('#' + hashElement).attr('value', $.sha256(password + nonce));
$('#' + passwordElement).attr('value', '');
}
The problem is when I press Login nothing happens. The page does not refresh. It behaves as is I am clicking nothing.
EDIT: I have now checked the sources in developer tools of Chrome. It is telling me uncaught reference error: getPasswordHash is not defined
http://i.imgur.com/LOW9E0f.png
Thanks in advance.
You need a Database with users in it. To create the DB open the manager console and type Enable-Migrations -ContextTypeName [ContextClassName]
this should create a migrations folder and then you need to register a user before signing in.
EDIT : Make sure you have a Login function inside of the Accounts controller
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.