public void AuthenticateUser_Test1()
        {
            string TestUser = "******";
            string TestPass = "******";
            bool   Actual   = _testTarget.AuthenticateUser(TestUser, TestPass);

            Assert.IsTrue(Actual);
            Assert.IsTrue(_sucessfulAuthenticationRequests.Messages[0] == "AuthenticateUser");
        }
예제 #2
0
        public ActionResult Login([Bind(Include = "emailAddress, password")] Login model)
        {
            if (ModelState.IsValid)
            {
                bool authenticated = false;
                var  profileData   = db.ProfileData.Where(user => user.Email == model.emailAddress).FirstOrDefault();
                if (profileData != null)
                {
                    var userCredentials = db.AccountData.Where(user => user.ProfileId == profileData.Id).FirstOrDefault();
                    authenticated = Authentication.AuthenticateUser(model.emailAddress, profileData.Email, model.password, userCredentials.Hash, userCredentials.Salt);
                }
                if (authenticated)
                {
                    //Create user session
                    var user = new User()
                    {
                        Id         = profileData.Id,
                        Voornaam   = profileData.Voornaam,
                        Achternaam = profileData.Achternaam
                    };
                    Session["User"] = user;
                    return(RedirectToAction("About", "Home"));
                }
                else
                {
                    ModelState.AddModelError("LoginError", "De gebruikersnaam/wachtwoord is incorrect");

                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
예제 #3
0
        public IActionResult Login([Bind("emailAddress, password")] Login model)
        {
            if (ModelState.IsValid)
            {
                bool authenticated = false;
                var  profileData   = db.ProfileData.Where(user => user.Email == model.emailAddress).FirstOrDefault();
                if (profileData != null)
                {
                    var userCredentials = db.AccountData.Where(user => user.ProfileId == profileData.Id).FirstOrDefault();
                    authenticated = Authentication.AuthenticateUser(model.emailAddress, profileData.Email, model.password, userCredentials.Hash, userCredentials.Salt);
                }
                if (authenticated)
                {
                    HttpContext.Session.SetInt32("UserId", profileData.Id);
                    HttpContext.Session.SetInt32("AccountType", Int32.Parse(profileData.AccountType.ToString()));
                    return(RedirectToAction("Privacy", "Home"));
                }
                else
                {
                    ModelState.AddModelError("LoginError", "De gebruikersnaam/wachtwoord is incorrect");

                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
예제 #4
0
        public bool AuthenticationUser(string userName, string password)
        {
            var status       = new Authentication();
            var statusReturn = status.AuthenticateUser(userName, password);

            return(statusReturn);
        }
예제 #5
0
 private static void AttemptAuthentication(string userName, string nonHashedPassword)
 {
     if (Authentication.AuthenticateUser(userName, nonHashedPassword))
     {
         Console.WriteLine("  ~~~ CORRECT ~~~");
     }
     else
     {
         Console.WriteLine("  !!! FAILED !!!");
         Exception e = new Exception("Fail");
         throw e;
     }
 }
        private void AuthenticateWithVault()
        {
            string resultMessage;

            Invoke((Action)(() => progressBar1.Value = 0));
            Invoke((Action)(() => uxAuthStatus.Text = "Attempting login..."));
            Invoke((Action)(() => progressBar1.Text = "Attempting login..."));

            Application.DoEvents();

            var authenticationResult = Authentication.AuthenticateUser(uxAuthUserID.Text, uxAuthPassword.Text, uxAuthServerUrl.Text);

            if (authenticationResult.IsAuthenticated)
            {
                Invoke((Action)(() => uxAuthStatus.ForeColor = Color.Green));

                _vault = authenticationResult.Vault;

                _serverCulture = _vault.Configurations.GetConfigurationSetting("CurrentCulture").Replace("_", "-");

                resultMessage = string.Format("Logged In - Target Vault Culture is {0}", _serverCulture);

                Invoke((Action)(() => uxAuthStatus.Text = resultMessage));

                if (_profile != null)
                {
                    Invoke((Action)(() => SelectFormTemplate(_profile.ImportFormTemplateName)));

                    Invoke((Action)(() => SelectFormDashboard(_profile.ExportFormDashboardName)));
                }

                Invoke((Action)(() => tabControl1.SelectedTab = tabPage2));

                Invoke((Action)(EnableAllControls));

                Application.DoEvents();
            }
            else
            {
                Invoke((Action)(() => uxAuthStatus.ForeColor = Color.Red));
                _vault        = null;
                resultMessage = "Login Failed";
            }

            Invoke((Action)(() => progressBar1.Text = resultMessage));
            Invoke((Action)(() => uxAuthStatus.Text = resultMessage));

            Application.DoEvents();
        }
예제 #7
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        var UserName = Server.HtmlEncode(txtAccessCode.Text);
        var Password = Server.HtmlEncode(txtPassword.Text);
        var IsValid  = Authentication.AuthenticateUser(UserName, Password);

        if (IsValid)
        {
            Response.Redirect("~/management/modules/modules/regis.aspx");
        }
        else
        {
            Response.Redirect("default.aspx?err=AUT404");
        }
    }
예제 #8
0
        public async Task <DBResult> Login(AuthenticationModel model)
        {
            SupervisorModel result    = null;
            bool            hasError  = false;
            string          errorText = "";

            try
            {
                if (ModelState.IsValid || model != null)
                {
                    result = await Authentication.AuthenticateUser(model.Username, model.Password);

                    if (result == null)
                    {
                        return(new DBResult
                        {
                            status = !hasError ? "Success" : "Fail",
                            descripText = "Username/Password is not valid",
                            data = null
                        });
                    }
                }
                else
                {
                    hasError = true;
                }
            }
            catch (Exception e)
            {
                hasError = true;

                return(new DBResult
                {
                    status = !hasError ? "Success" : "Fail",
                    descripText = e.Message.ToString(),
                    data = null
                });
            }
            return(new DBResult {
                status = !hasError ? "Success" : "Fail", descripText = errorText, data = new SupervisorModel {
                    SupervisorId = result.SupervisorId, Name = result.Name, Surname = result.Surname, CemeteryId = result.CemeteryId, UserName = result.UserName, SupervisorPassword = result.SupervisorPassword
                }
            });
        }
예제 #9
0
        public void HandlePost(Request request, string requestedFile)
        {
            string username = request.formData["Username"];
            string password = request.formData["Password"];

            if (_authentication.AuthenticateUser(username, password))
            {
                string path = "http://" + ConfigurationManager.AppSettings.Get("ipadress") + ":"
                              + AppConfigProcessor.Get().WebPort + "/admin/settings.html";

                throw new RedirectException(path);
            }
            else
            {
                string path = "http://" + ConfigurationManager.AppSettings.Get("ipadress") + ":"
                              + AppConfigProcessor.Get().WebPort + "/admin/index.html";

                throw new RedirectException(path);
            }
        }
예제 #10
0
        public HttpResponseMessage CheckForExpiringNodesByUser()
        {
            HttpResponseMessage res;

            try
            {
                // Only allow one instance to run at a time
                const string appName = "CheckForExpiringNodesByUser";
                bool         createdNew;
                _mutex = new Mutex(true, appName, out createdNew);

                if (!createdNew)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }

                // Check that the correct credentials have been supplied
                var content = Request.Content.ReadAsStringAsync().Result;
                if (!Authentication.AuthenticateUser(content))
                {
                    return(Request.CreateResponse(HttpStatusCode.Forbidden));
                }

                // OK, carry on
                res = GetExpiringNodesByUser();
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
            finally
            {
                _mutex.Dispose();
            }

            return(res);
        }