Example #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());
        }
Example #2
0
        private void btnGiaiMa_Click(object sender, EventArgs e)
        {
            if (txtGMBanMa.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập bản rõ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtGMKhoa.Text == "")
            {
                MessageBox.Show("Key không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                int z = Int32.Parse(txtGMKhoa.Text);
            }
            catch
            {
                MessageBox.Show("Key phải là số nguyên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            txtGMBanRo.Text = Ceasar.decrypt(txtGMBanMa.Text, Int32.Parse(txtGMKhoa.Text));
            //MessageBox.Show("Giải mã thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        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");
     }
 }
 private void btnGiaiMaFile_Click(object sender, EventArgs e)
 {
     if (txtPathInputGiaiMa.Text != "")
     {
         if (mnrKeyGiaiMa.Text != "" || txtZGiaima.Text != "")
         {
             dichChuyen_Key = int.Parse(mnrKeyGiaiMa.Text);
             string dichChuyen_Input = inputGiaima;
             string dungluong        = filenameinputGiaima.Split(new char[] { '_' })[1];
             filenameoutputGiaima          = "Decrypt_" + dungluong + "_11.txt";
             filenameoutputGiaimaChallenge = "Decrypt_Challenge" + dungluong + "_11.txt";
             OutputText.Text = Ceasar.Decipher(dichChuyen_Input, dichChuyen_Key, dichChuyen_Z);
             outputGiaima    = Ceasar.Decipher(dichChuyen_Input, dichChuyen_Key, dichChuyen_Z);
             FileHelper.WriteFile(@"" + filenameoutputGiaima + "", "Di chuyển", dichChuyen_Z, dichChuyen_Key.ToString(), outputGiaima);
             txtOutputGiaiMaName.Text = System.IO.Path.GetFileName(@"" + filenameoutputGiaima + "");
             FileHelper.WriteFile(@"" + filenameoutputGiaimaChallenge + "", "Di chuyển", dichChuyen_Z, outputGiaima);
             txtOutputGiaiMaChallengeName.Text = System.IO.Path.GetFileName(@"" + filenameoutputGiaimaChallenge + "");
         }
         else
         {
             MessageBox.Show("Chưa nhập đủ thông tin!!!");
         }
     }
     else
     {
         MessageBox.Show("Chưa chọn file để giải mã");
     }
 }
        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();
        }
Example #7
0
        private void btnGMThamMa_Click(object sender, EventArgs e)
        {
            if (txtGMBanMa.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập bản rõ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            txtGMBanRo.Text = Ceasar.decrypt(txtGMBanMa.Text);
        }
        private async Task LoadAsync(IdentityUser user)
        {
            var email = await _userManager.GetEmailAsync(user);

            Email = Ceasar.Decipher(email, CipherKey);

            Input = new InputModel
            {
                NewEmail = Ceasar.Decipher(email, CipherKey)
            };

            IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
        }
        private async Task LoadAsync(IdentityUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username = Ceasar.Decipher(userName, CipherKey);

            Input = new InputModel
            {
                PhoneNumber = phoneNumber
            };
        }
 private void btnGiaiMa_Click(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.Decipher(InputText.Text, dichChuyen_Key, dichChuyen_Z);
 }
Example #11
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());
        }
Example #12
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;
            }
        }
Example #13
0
        public async Task <IActionResult> Index()
        {
            var allUsers   = _userManager.Users.ToList();
            var allUsersVM = new List <IdentityUserViewModel>();

            foreach (var user in allUsers)
            {
                var roles = await _userManager.GetRolesAsync(user);

                var role = roles.FirstOrDefault();
                IdentityUserViewModel identityUserVM = new IdentityUserViewModel
                {
                    Id       = user.Id,
                    UserName = Ceasar.Decipher(user.UserName, CipherKey),
                    Role     = role
                };
                allUsersVM.Add(identityUserVM);
            }
            return(View(allUsersVM));
        }
Example #14
0
 public CeasarTest()
 {
     _ceasar = new Ceasar();
 }
Example #15
0
        private void button1_Click(object sender, EventArgs e)
        {
            String ka      = textBox1.Text;
            String string1 = "";

            try
            {
                // tao instance cua StreamReader de doc mot file.
                // lenh using cung duoc su dung de dong StreamReader.
                using (StreamReader sr = new StreamReader(ka))
                {
                    string line;

                    // doc va hien thi cac dong trong file cho toi
                    // khi tien toi cuoi file.
                    while ((line = sr.ReadLine()) != null)
                    {
                        string1 = string1 + line;
                        Console.WriteLine(line);
                    }
                }

                Console.ReadKey();
            }
            catch (Exception g)
            {
                // thong bao loi.
                Console.WriteLine("Khong the doc du lieu tu file da cho: ");
                Console.WriteLine(g.Message);
            }
            //sao chep
            string stringz = @"abcdefghijklmnopqrstuvwxyz";
            int    t0      = 0;
            string tr0;

            tr0 = Ceasar.Decipher(string1, t0, stringz);
            string tr1 = "";

            tr1 = Ceasar.Decipher(string1, 1, stringz);
            string tr2 = "";

            tr2 = Ceasar.Decipher(string1, 2, stringz);
            string tr3 = "";

            tr3 = Ceasar.Decipher(string1, 3, stringz);
            string tr4 = "";

            tr4 = Ceasar.Decipher(string1, 4, stringz);

            string tr5 = "";

            tr5 = Ceasar.Decipher(string1, 5, stringz);
            string tr6 = "";

            tr6 = Ceasar.Decipher(string1, 6, stringz);
            string tr7 = "";

            tr7 = Ceasar.Decipher(string1, 7, stringz);
            string tr8 = "";

            tr8 = Ceasar.Decipher(string1, 8, stringz);
            string tr9 = "";

            tr9 = Ceasar.Decipher(string1, 9, stringz);
            string tr10 = "";

            tr10 = Ceasar.Decipher(string1, 10, stringz);
            string tr11 = "";

            tr11 = Ceasar.Decipher(string1, 11, stringz);
            string tr12 = "";

            tr12 = Ceasar.Decipher(string1, 12, stringz);
            string tr13 = "";

            tr13 = Ceasar.Decipher(string1, 13, stringz);
            string tr14 = "";

            tr14 = Ceasar.Decipher(string1, 14, stringz);
            string tr15 = "";

            tr15 = Ceasar.Decipher(string1, 15, stringz);
            string tr16 = "";

            tr16 = Ceasar.Decipher(string1, 16, stringz);
            string tr17 = "";

            tr17 = Ceasar.Decipher(string1, 17, stringz);
            string tr18 = "";

            tr18 = Ceasar.Decipher(string1, 18, stringz);
            string tr19 = "";

            tr19 = Ceasar.Decipher(string1, 19, stringz);
            string tr20 = "";

            tr20 = Ceasar.Decipher(string1, 20, stringz);
            string tr21 = "";

            tr21 = Ceasar.Decipher(string1, 21, stringz);
            string tr22 = "";

            tr22 = Ceasar.Decipher(string1, 22, stringz);
            string tr23 = "";

            tr23 = Ceasar.Decipher(string1, 23, stringz);
            string tr24 = "";

            tr24 = Ceasar.Decipher(string1, 24, stringz);
            string tr25 = "";

            tr25 = Ceasar.Decipher(string1, 25, stringz);
            string tr26 = "";

            tr26           = Ceasar.Decipher(string1, 26, stringz);
            textBox2.Text  = tr0;
            textBox3.Text  = tr1;
            textBox4.Text  = tr2;
            textBox5.Text  = tr3;
            textBox6.Text  = tr4;
            textBox7.Text  = tr5;
            textBox8.Text  = tr6;
            textBox9.Text  = tr7;
            textBox10.Text = tr8;
            textBox11.Text = tr9;
            textBox12.Text = tr10;
            textBox13.Text = tr11;
            textBox14.Text = tr12;
            textBox15.Text = tr13;
            textBox16.Text = tr14;
            textBox17.Text = tr16;
            textBox18.Text = tr17;
            textBox19.Text = tr18;
            textBox20.Text = tr19;
            textBox21.Text = tr20;
            textBox22.Text = tr21;
            textBox23.Text = tr22;
            textBox24.Text = tr23;
            textBox25.Text = tr24;
            textBox26.Text = tr25;
            textBox27.Text = tr26;
        }