I am just starting to delve into ASP .NET's MVC and AJAX design, and I have concerns about the security of the Controller when the website is deployed.
For fun, I created an admin panel that requires a username and password. The input information is then AJAX submitted to an ActionResult method in the Controller for comparison before returning the response back to the client-side.
My main worry is how vulnerable my Controller is and whether someone could easily access the hard-coded password stored within it.
While this site is not meant for professional use and is simply for a university club, I want to ensure that even an average Computer Science student couldn't "break in" out of frustration or curiosity.
Question: Is using password validation within the Controller considered secure for an ASP .NET MVC web-deployed application? Please provide your reasoning based on best practices.
The actual code is provided below for reference (domain omitted for privacy reasons).
Note: While I recognize that the use of JavaScript may pose risks, I specifically seek feedback on the security of the password check implemented through AJAX and the Controller.
View (Admin/)
// executes preloadFunc immediately
window.onpaint = preloadFunc();
function preloadFunc() {
var prompting = prompt("Please enter the password", "****");
if (prompting != null) {
$.ajax({
url: "/Admin/magicCheck",
type: "POST",
data: "magic=" + prompting,
success: function (resp) {
if (resp.Success) {
// continue loading page
}
else {
// incorrect password, prompt again
preloadFunc();
}
},
error: function () {
// prompt again
preloadFunc();
}
});
}
else {
// User clicked cancel
window.stop();
window.location.replace("google.com");
}
}
Controller (ActionResult Snippet)
[HttpPost]
public ActionResult magicCheck(string magic)
{
bool success = false;
if (magic == "pass")
{
success = true;
}
else
{
success = false;
}
return Json(new { Success = success });
}
Given my limited experience with MVC and AJAX, as well as security protocols, I am seeking insights on the specific security measures implemented in the Controller, particularly in the context of web deployment for this basic password verification setup.