Exemplo n.º 1
0
 private static bool IsValidPartTwo(PasswordInput input)
 {
     return(input.Password.Where((c, index) => c == input.Letter &&
                                 (index + 1 == input.MinRange || index + 1 == input.MaxRange))
            .Count() == 1);
 }
Exemplo n.º 2
0
        private static bool IsValid(PasswordInput input)
        {
            var letterOccurances = input.Password.Count(pwChar => pwChar.Equals(input.Letter));

            return(letterOccurances >= input.MinRange && letterOccurances <= input.MaxRange);
        }
Exemplo n.º 3
0
        private static async Task OrderDomains(ACMEClient acmeClient, params string[] domainNames)
        {
            IEnumerable <OrderIdentifier> domains = domainNames.Select(domain => new OrderIdentifier {
                Type = ChallengeType.DNSChallenge, Value = domain
            });

            Uri[] validations = null;
            Order order       = null;

            while (order == null)
            {
                order = await NewOrderAsync(acmeClient, domains);

                if (order == null)
                {
                    Console.WriteLine("Failed.. retrying");
                    await Task.Delay(5000);
                }
            }

            // todo: save order identifier
            Console.WriteLine($"Order location: {order.Location}");

            validations = order.Authorizations;
            IEnumerable <AuthorizationChallengeResponse> auths = await RetrieveAuthz(acmeClient, validations);

            foreach (AuthorizationChallengeResponse item in auths)
            {
                if (item.Status == ACMEStatus.Valid)
                {
                    Console.WriteLine("Domain already validated succesfully.");
                    continue;
                }

                AuthorizationChallenge validChallenge = item.Challenges.Where(challenge => challenge.Status == ACMEStatus.Valid).FirstOrDefault();
                if (validChallenge != null)
                {
                    Console.WriteLine("Found a valid challenge, skipping domain.");
                    Console.WriteLine(validChallenge.Type);
                    continue;
                }

                IEnumerable <AuthorizationChallenge> applicableChallenges = item.Wildcard ? item.Challenges.Where(x => x.Type == "dns-01") :
                                                                            item.Challenges;

                foreach (AuthorizationChallenge challenge in applicableChallenges)
                {
                    Console.WriteLine($"Status: {challenge.Status}");
                    Console.WriteLine($"Challenge: {challenge.Url}");
                    Console.WriteLine($"Type: {challenge.Type}");
                    Console.WriteLine($"Token: {challenge.Token}");
                    Console.WriteLine($"Value: {challenge.AuthorizationToken}");

                    if (challenge.Type == "http-01")
                    {
                        File.WriteAllText(challenge.Token, challenge.AuthorizationToken);
                        Console.WriteLine($"File saved as: {challenge.Token} in working directory.");
                        Console.WriteLine($"Please upload the file to {item.Identifier.Value}/.well-known/acme-challenge/{challenge.Token}");
                    }
                    else if (challenge.Type == "dns-01")
                    {
                        Console.WriteLine($"Please create a text entry for _acme-challenge.{item.Identifier.Value} with value: {challenge.AuthorizationToken}");
                    }
                    else
                    {
                        Console.WriteLine($"Unknown challenge type encountered '{challenge.Type}'. Please handle accourdingly.");
                    }

                    var result = HandleConsoleInput("Challenge completed? [y/n]", new[] { "y", "yes", "n", "no" });
                    if (result == "y" || result == "yes")
                    {
                        Console.WriteLine("Validating challenge");
                        var validation = await ValidateChallengeCompletion(challenge, item.Identifier.Value);

                        if (validation)
                        {
                            AuthorizationChallengeResponse c = await CompleteChallenge(acmeClient, challenge, challenge.AuthorizationToken);

                            while (c.Status == ACMEStatus.Pending)
                            {
                                await Task.Delay(5000);

                                c = await acmeClient.GetAuthorizationChallengeAsync(challenge.Url);
                            }

                            Console.WriteLine($"Challenge Status: {c.Status}");
                            if (c.Status == ACMEStatus.Valid)
                            {
                                // no reason to keep going, we have one succesfull challenge!
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine($"Validation failed for {item.Identifier.Value}");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Skipping challenge");
                    }
                }
            }

            foreach (Uri challenge in order.Authorizations)
            {
                AuthorizationChallengeResponse c;
                do
                {
                    c = await acmeClient.GetAuthorizationChallengeAsync(challenge);
                }while (c == null || c.Status == ACMEStatus.Pending);

                if (c.Status == ACMEStatus.Invalid)
                {
                    Console.WriteLine($"Failed to validate domain {c.Identifier.Value}. Aborting");
                    return;
                }
            }

            order = await acmeClient.UpdateOrderAsync(order);

            Console.WriteLine($"Order status:{order.Status}");

            while (order.Status == ACMEStatus.Processing)
            {
                Thread.Sleep(500);
                Console.WriteLine("Order status = processing; updating..");
                order = await acmeClient.UpdateOrderAsync(order);
            }

            var certKey = new RSACryptoServiceProvider(4096);

            SaveRSAKeyToFile(certKey, $"{FixFilename(order.Identifiers[0].Value)}.key");

            Order certOrder = null;

            try
            {
                certOrder = await acmeClient.RequestCertificateAsync(order, certKey);

                while (certOrder.Status == ACMEStatus.Processing)
                {
                    Thread.Sleep(500);
                    Console.WriteLine("Order status = processing; updating..");
                    certOrder = await acmeClient.UpdateOrderAsync(certOrder);
                }

                Console.WriteLine(certOrder.Status);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            X509Certificate2 cert = await acmeClient.GetCertificateAsync(certOrder);

            var certdata          = cert.Export(X509ContentType.Cert);
            var publicKeyFilename = $"{FixFilename(certOrder.Identifiers[0].Value)}.crt";

            File.WriteAllBytes(publicKeyFilename, certdata);
            Console.WriteLine($"Public certificate written to file {publicKeyFilename}");

            // combine the two!
            X509Certificate2 properCert = cert.CopyWithPrivateKey(certKey);

            Console.WriteLine("Enter password to secure PFX");
            System.Security.SecureString password = PasswordInput.ReadPassword();
            var pfxData = properCert.Export(X509ContentType.Pfx, password);

            var privateKeyFilename = $"{FixFilename(certOrder.Identifiers[0].Value)}.pfx";

            File.WriteAllBytes(privateKeyFilename, pfxData);
            Console.WriteLine($"Private certificate written to file {privateKeyFilename}");
        }
Exemplo n.º 4
0
        /// <summary>
        /// </summary>
        /// <param name="passwordInput"></param>
        /// <param name="checkLastPassword"></param>
        public ServiceResult ChangePassword(PasswordInput passwordInput, bool checkLastPassword = true)
        {
            var userDetail = Resolve <IUserService>().GetUserDetail(passwordInput.UserId);

            if (userDetail == null)
            {
                return(ServiceResult.FailedWithMessage("您访问的用户不存在"));
            }

            var result = ServiceResult.Failed;

            if (passwordInput.Password.IsNullOrEmpty())
            {
                return(ServiceResult.FailedWithMessage("密码不能为空"));
            }

            if (passwordInput.Password.Length < 6)
            {
                return(ServiceResult.FailedWithMessage("密码长度不能小于6"));
            }

            if (passwordInput.Password != passwordInput.ConfirmPassword)
            {
                return(ServiceResult.FailedWithMessage("确认密码与确认密码不相同"));
            }

            // 检查老密码
            if (checkLastPassword)
            {
                if (passwordInput.Type == PasswordType.LoginPassword)
                {
                    if (!passwordInput.LastPassword.ToMd5HashString()
                        .Equals(userDetail.Detail.Password, StringComparison.OrdinalIgnoreCase))
                    {
                        return(ServiceResult.FailedWithMessage("原始登录密码不正确"));
                    }
                }

                if (passwordInput.Type == PasswordType.PayPassword)
                {
                    if (!passwordInput.LastPassword.ToMd5HashString().Equals(userDetail.Detail.PayPassword,
                                                                             StringComparison.OrdinalIgnoreCase))
                    {
                        return(ServiceResult.FailedWithMessage("原始支付密码不正确"));
                    }
                }
            }

            if (passwordInput.Type == PasswordType.LoginPassword)
            {
                if (_userDetailRepository.ChangePassword(passwordInput.UserId,
                                                         passwordInput.Password.ToMd5HashString()))
                {
                    Resolve <IUserService>().DeleteUserCache(userDetail.Id, userDetail.UserName);
                    return(ServiceResult.Success);
                }
            }

            if (passwordInput.Type == PasswordType.PayPassword)
            {
                if (!RegexHelper.CheckPayPasswrod(passwordInput.Password))
                {
                    return(ServiceResult.FailedWithMessage("支付密码必须为六位数字"));
                }

                if (_userDetailRepository.ChangePayPassword(passwordInput.UserId,
                                                            passwordInput.Password.ToMd5HashString()))
                {
                    Resolve <IUserService>().DeleteUserCache(userDetail.Id, userDetail.UserName);
                    return(ServiceResult.Success);
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            Form passwordForm = new PasswordInput(controller, dataGridView.SelectedRows[0].Cells[3].Value.ToString().Trim());

            passwordForm.ShowDialog();
        }
Exemplo n.º 6
0
        public ApiResult UpdatePassword([FromBody] ViewAdminEdit view)
        {
            var passwordInput = new PasswordInput
            {
                Password        = view.Password,
                ConfirmPassword = view.ConfirmPassword,
                UserId          = view.EditUserId
            };

            var editUser = Resolve <IUserService>().GetSingle(view.EditUserId);

            if (editUser == null)
            {
                return(ApiResult.Failure("要编辑的用户ID对应用户信息不存在"));
            }

            view.User = editUser;

            //修改登录密码
            if (view.Type == 1)
            {
                passwordInput.Type = PasswordType.LoginPassword;
                var reuslt = Resolve <IUserDetailService>().ChangePassword(passwordInput, false);
                if (reuslt.Succeeded)
                {
                    Resolve <IUserService>()
                    .Log($"管理员修改会员的登录密码,会员ID为{view.User.Id},会员名{view.User.UserName},姓名{view.User.Name}");
                    if (view.SendPassword)
                    {
                        //  _messageManager.AddRawQueue(view.User.Mobile,
                        //    $"管理员已成功修改了您的登录密码,新的登录密码为{view.Password},请尽快登录系统,并修改登录密码");
                    }
                }
                else
                {
                    return(ApiResult.Failure("服务异常:登录密码修改失败,请稍后在试"));
                }
            }

            if (view.Type == 2)
            {
                passwordInput.Type = PasswordType.PayPassword;
                var reuslt = Resolve <IUserDetailService>().ChangePassword(passwordInput, false);
                if (reuslt.Succeeded)
                {
                    Resolve <IUserService>().Log(
                        $"管理员修改会员的支付密码,会员ID为{view.User.Id},会员名{view.User.UserName},姓名{view.User.Name}"
                        );
                    if (view.SendPassword)
                    {
                        //  _messageManager.AddRawQueue(view.User.Mobile,
                        //   $"管理员已成功修改了您的支付密码,新的登录密码为{view.Password},请尽快登录系统,并修改支付密码");
                    }
                }
                else
                {
                    return(ApiResult.Failure("服务异常:支付密码修改失败,请稍后在试" + reuslt));
                }
            }

            return(ApiResult.Success("密码修改成功"));
        }
Exemplo n.º 7
0
 public void ClickOnPasswordInput()
 {
     PasswordInput.Click();
 }
Exemplo n.º 8
0
 private void ImgShowHide_PreviewMouseUp(object sender, MouseEventArgs e)
 {
     HidePassword();
     PasswordInput.Focus();
 }
Exemplo n.º 9
0
 // PasswordInput
 public string GetPasswordInputText()
 {
     return(PasswordInput.GetAttribute(VALUE_ATTRIBUTE));
 }
Exemplo n.º 10
0
 public void SetPasswordInput(string text)
 {
     PasswordInput.SendKeys(text);
 }
Exemplo n.º 11
0
 public void SendKeysToPasswordInput(string keys)
 {
     PasswordInput.SendKeys(keys);
 }
Exemplo n.º 12
0
 public void FillPassword(string password)
 {
     PasswordInput.SendKeys(password);
 }
Exemplo n.º 13
0
        void LoadImages()
        {
            var openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Zip files|*.zip";

            if (!openFileDialog.ShowDialog() == true)
            {
                Application.Current.Shutdown();
                return;
            }

            var passwordSet = false;

            Images.Clear();
            Albums.Clear();

            using (var file = new ZipFile(openFileDialog.FileName))
            {
                AlbumModel currentAlbum = null;

                foreach (ZipEntry entry in file)
                {
                    if (entry.IsCrypted && !passwordSet)
                    {
                        var input = new PasswordInput();
                        if (!input.ShowDialog() == true)
                        {
                            Application.Current.Shutdown();
                            return;
                        }

                        file.Password = input.Password;
                        passwordSet = true;
                    }

                    if (!entry.IsFile)
                    {
                        var album = new AlbumModel(this);
                        album.Name = entry.Name;
                        currentAlbum = album;

                        Albums.Add(album);
                    }
                    else
                    {
                        var stream = file.GetInputStream(entry);
                        var buffer = new byte[4096];
                        var image = new BitmapImage();
                        var memoryStream = new MemoryStream();

                        try
                        {
                            StreamUtils.Copy(stream, memoryStream, buffer);

                            if (Path.GetExtension(entry.Name).ToLowerInvariant().Contains("jpg"))
                            {
                                var jpg = new Bitmap(memoryStream);

                                var stream2 = new MemoryStream();

                                jpg.Save(stream2, ImageFormat.Png);

                                memoryStream.Dispose();
                                memoryStream = stream2;
                            }

                            image.BeginInit();
                            image.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
                            image.CacheOption = BitmapCacheOption.OnLoad;
                            image.UriSource = null;
                            image.StreamSource = memoryStream;
                            image.EndInit();

                            Images.Add(new ImageModel()
                            {
                                Name = entry.Name,
                                Album = currentAlbum,
                                Image = image
                            });
                        }
                        finally
                        {
                            memoryStream.Dispose();
                        }
                    }
                }

                ImageIndex = 0;
            }
        }
Exemplo n.º 14
0
 public void enterPassword(string password)
 {
     PasswordInput.Clear();
     PasswordInput.SendKeys(password);
 }
Exemplo n.º 15
0
 public void ClearPasswordInput()
 {
     PasswordInput.Clear();
 }
 public void Login(string email, string password)
 {
     EmailInput.SendKeys(email);
     PasswordInput.SendKeys(password);
     SignInButton.Click();
 }
Exemplo n.º 17
0
 /// <summary>
 /// Inputs user password to Password Input on page
 /// </summary>
 /// <param name="user">User data in IUser format</param>
 public void InputTextInPasswordInput(IUser user)
 {
     PasswordInput.SendKeys(user.GetPassword());
 }
Exemplo n.º 18
0
 /// <summary>
 /// Enter the user credentials
 /// </summary>
 /// <param name="userName">The user name</param>
 /// <param name="password">The user password</param>
 public void EnterCredentials(string userName, string password)
 {
     UserNameInput.SendKeys(userName);
     PasswordInput.SendKeys(password);
 }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     PasswordInput.Focus();
 }