Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Ceasar.Encipher(Input.Email, CipherKey), Input.Password, Input.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");
                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task <IActionResult> OnPostChangeEmailAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (!ModelState.IsValid)
            {
                await LoadAsync(user);

                return(Page());
            }

            var email = await _userManager.GetEmailAsync(user);

            if (Input.NewEmail != Ceasar.Decipher(email, CipherKey))
            {
                var code = await _userManager.GenerateChangeEmailTokenAsync(user, Ceasar.Encipher(Input.NewEmail, CipherKey));

                await ChgangeEmailAndLogout(user, code);

                return(RedirectToAction("Index", "Home"));
            }

            StatusMessage = "Your email is unchanged.";
            return(RedirectToPage());
        }
 private void btnMaHoaFile_Click(object sender, EventArgs e)
 {
     if (txtPathInputMaHoa.Text != "")
     {
         if (txtKeyMahoa.Text != "" && txtZMahoa.Text != "")
         {
             dichChuyen_Key = int.Parse(txtKeyMahoa.Text);
             dichChuyen_Z   = txtZMahoa.Text;
             string dichChuyen_Input = inputMahoa;
             string dungluong        = filenameinputMahoa.Split(new char[] { '_' })[1];
             filenameoutputMahoa          = "Enc_" + dungluong + "_11.txt";
             filenameoutputMahoaChallenge = "Challenge_" + dungluong + "_11.txt";
             outputMahoa = Ceasar.Encipher(dichChuyen_Input, dichChuyen_Key, dichChuyen_Z);
             FileHelper.WriteFile(@"" + filenameoutputMahoa + "", "Di chuyển", dichChuyen_Z, dichChuyen_Key.ToString(), outputMahoa);
             txtOutputName.Text = System.IO.Path.GetFileName(@"" + filenameoutputMahoa + "");
             FileHelper.WriteFile(@"" + filenameoutputMahoaChallenge + "", "Di chuyển", dichChuyen_Z, outputMahoa);
             txtOutputChallengeName.Text = System.IO.Path.GetFileName(@"" + filenameoutputMahoaChallenge + "");
         }
         else
         {
             MessageBox.Show("Chưa nhập đủ thông tin!!!");
             return;
         }
     }
     else
     {
         MessageBox.Show("Chưa chọn file để mã hóa");
     }
 }
        public async Task ChgangeEmailAndLogout(IdentityUser user, string code)
        {
            await _userManager.ChangeEmailAsync(user, Ceasar.Encipher(Input.NewEmail, CipherKey), code);

            await _userManager.SetUserNameAsync(user, Ceasar.Encipher(Input.NewEmail, CipherKey));

            await _signInManager.SignOutAsync();
        }
 //abcdefghijklmnopqrstuvwxyz
 private void btnMaHoa_Click_1(object sender, EventArgs e)
 {
     if (txtK.Text != "" && txtZ.Text != "")
     {
         dichChuyen_Key = int.Parse(txtK.Text);
         dichChuyen_Z   = txtZ.Text;
     }
     else
     {
         MessageBox.Show("Chưa nhập đủ thông tin!!");
         return;
     }
     OutputText.Text = Ceasar.Encipher(InputText.Text, dichChuyen_Key, dichChuyen_Z);
 }
Esempio n. 6
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Ceasar.Encipher(Input.Email, CipherKey), Email = Ceasar.Encipher(Input.Email, CipherKey)
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, "Customer");

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Esempio n. 7
0
        private void ExcuteAlgorithm()
        {
            _result = new List <string>();
            int algor    = cbxAlgorithm.SelectedIndex;
            int progress = cbxProgress.SelectedIndex;

            switch (algor)
            {
            case 0:
                int key = int.Parse(rtbxKey.Text);
                if (progress == 0)
                {
                    foreach (var item in _data)
                    {
                        _result.Add(Ceasar.Encipher(item, key));
                    }
                }
                else
                {
                    foreach (var item in _data)
                    {
                        _result.Add(Ceasar.Decipher(item, key));
                    }
                }
                break;

            case 1:
                string khoa = rtbxKey.Text;
                if (progress == 0)
                {
                    foreach (var item in _data)
                    {
                        _result.Add(Playfair.PlayfairEncryption(item, khoa));
                    }
                }
                else
                {
                    foreach (var item in _data)
                    {
                        _result.Add(Playfair.PlayfairDecryption(item, khoa));
                    }
                }
                break;
            }
        }