public async void Test_GivenAUser_WhenCheckPassword_ThenResponseIsNotAltered()
        {
            var authFlowResponse = new AuthFlowResponse("sessionId", null, null, null, null);

            userStoreMock.Setup(mock => mock.StartValidatePasswordAsync(It.IsAny <CognitoUser>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(authFlowResponse)).Verifiable();
            var output = await userManager.CheckPasswordAsync(GetCognitoUser(), "password").ConfigureAwait(false);

            Assert.Equal(authFlowResponse, output);
            userStoreMock.Verify();
        }
Beispiel #2
0
        public async Task <IActionResult> PrivacyAsync()
        {
            CognitoUserManager userManager = new CognitoUserManager();
            var user = new Models.CognitoUser();

            user.UserName = "******";
            user.Password = "******";
            var ValidPassword = userManager.CheckPasswordAsync("*****@*****.**", "MytestPass141!");
            var y             = await ValidPassword;
            var x             = "asffdsf";/******/


            /***
             * Amazon.CognitoIdentityProvider.Model.ConfirmSignUpRequest confirmRequest = new ConfirmSignUpRequest()
             * {
             *  Username = "******",
             *  ClientId = "6aaambb1i02abdkokr2n4ohojl",
             *  ConfirmationCode = "343651"
             * };
             * AmazonCognitoIdentityProviderClient client = new AmazonCognitoIdentityProviderClient();
             * var confirmResult = await client.ConfirmSignUpAsync(confirmRequest);
             * var x = "";***/
            /**
             * Models.CognitoUser newuser = new Models.CognitoUser();
             * newuser.Password = "******";
             * newuser.Email = "*****@*****.**";
             * CognitoUserStore cognitoUserStore = new CognitoUserStore();
             *
             * CancellationTokenSource source = new CancellationTokenSource();
             * CancellationToken token = source.Token;
             * await cognitoUserStore.CreateAsync(newuser);**/
            return(View());
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            CognitoUserManager _signInManager = CognitoUserManager.CognitoManager;
            CognitoUser        cognitoUser    = new CognitoUser()
            {
                UserName = model.Email
            };                                                                                  // "*****@*****.**" };
            var isvalid = await _signInManager.CheckPasswordAsync(cognitoUser, model.Password); // "crig7wee*uy7TANT");

            if (isvalid)
            {
                Session["IdToken"] = cognitoUser.IdToken;
                SignInAsync(cognitoUser, true);
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> Login(String Email, String Password)
        {
            CognitoUserManager userManager = new CognitoUserManager();
            var ValidPassword = await userManager.CheckPasswordAsync(Email, Password);

            if (ValidPassword.Equals(true))
            {
                return(RedirectToAction("Index", "Dashboard"));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await _cognitoUserManager.CheckPasswordAsync(new CognitoUser { Email = model.Email, UserName = model.Email }, model.Password);

            if (result)
            {
                FormsAuthentication.SetAuthCookie(model.Email, false);

                var    authTicket      = new FormsAuthenticationTicket(1, model.Email, DateTime.Now, DateTime.Now.AddMinutes(20), false, "");
                string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                HttpContext.Response.Cookies.Add(authCookie);
                return(RedirectToAction("Index", "Home"));
            }

            else
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            //switch (result)
            //{
            //    case SignInStatus.Success:
            //        return RedirectToLocal(returnUrl);
            //    case SignInStatus.LockedOut:
            //        return View("Lockout");
            //    case SignInStatus.RequiresVerification:
            //        return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            //    case SignInStatus.Failure:
            //    default:
            //        ModelState.AddModelError("", "Invalid login attempt.");
            //        return View(model);
            //}
            return(View(model));
        }