Ejemplo n.º 1
0
        static void Main()
        {
            UserInfor        users = new UserInfor();
            List <UserInfor> list  = users.GetUserList();

            foreach (var user in list)
            {
                if (Valid_password.isValid(user.UserName, user.Email, user.Init_Password))
                {
                    Console.WriteLine("{0} has a valid password", user.UserName);
                }
                else
                {
                    foreach (var err in Valid_password.ErrorMessage)
                    {
                        Console.WriteLine(err);
                    }
                    Valid_password.ErrorMessage.Clear();
                    string newpass = Generator.generate(user.UserName, user.Email);
                    Console.WriteLine("New password is " + newpass);
                }
            }

            Write_To helper = new Write_To();

            helper.wirteCSV(list);
            helper.writexml(list);
        }
Ejemplo n.º 2
0
        public static string generate(string userName, string email)
        {
            const string allowedChars =
                "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~@#$%^&*+=|<>/\\!’?”-:,;()[]{}";
            int           len1 = allowedChars.Length;
            StringBuilder sb   = new StringBuilder();
            Random        rnd  = new Random();
            int           len2 = rnd.Next(8, 20);

            for (int i = 0; i < len2; i++)
            {
                int idx = rnd.Next(len1);
                sb.Append(allowedChars[idx]);
            }
            string res = sb.ToString();

            return(Valid_password.isValid(userName, email, res) ? res : generate(userName, email));
        }