I am trying to build a login screen for my website, I would like to make it work without having to refresh the page (using AJAX). I have decided to use JQuery AJAX for this purpose to call an ASP.net WebMethod using the code below.
myPage.aspx
$.ajax({
type: "POST",
url: '<%= ResolveUrl("myPage.aspx/GetLogin") %>',
data: '{username: "' + $("#<%=txtUsername.ClientID%>")[0].value + '" }, {password: "' + $("#<%=txtPassword.ClientID%>")[0].value + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (response) {
if(result.d == true) {
LogIn();
}
else {
LogInFailed();
}
}
});
myPage.cs
[WebMethod]
public static bool LogIn(string username, string password)
{
bool result = CheckCredentials();
return result;
}
The question is, is this code secure enough? is this the right way to make a login asynchronously? is it secure to expose this LogIn publicly?