Esempio n. 1
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            HikvisionPassword hikvisionPassword = new HikvisionPassword();

            pwdResetCodeTextBox.Text = string.Empty;

            errorProvider.Clear();

            bool hasError = false;

            string serial_number = serialNumberTextBox.Text;

            if (hikvisionPassword.ValidateSerialNumber(serial_number) == false)
            {
                errorProvider.SetError(serialNumberTextBox, "Invalid serial number");

                hasError = true;
            }

            DateTime dateTime = dateTimePicker.Value;
            string   year     = Convert.ToString(dateTime.Year);
            string   month    = Convert.ToString(dateTime.Month);
            string   day      = Convert.ToString(dateTime.Day);

            if (hikvisionPassword.ValidateYear(year) == false)
            {
                errorProvider.SetError(dateTimePicker, "Invalid year");

                hasError = true;
            }
            else if (hikvisionPassword.ValidateMonth(month) == false)
            {
                errorProvider.SetError(dateTimePicker, "Invalid month");

                hasError = true;
            }
            else if (hikvisionPassword.ValidateDay(day) == false)
            {
                errorProvider.SetError(dateTimePicker, "Invalid day");

                hasError = true;
            }

            if (hasError == false)
            {
                pwdResetCodeTextBox.Text = hikvisionPassword.GeneratePasswordResetCode(serial_number, year, month, day);
            }
        }
Esempio n. 2
0
        static void Main()
        {
            Console.Clear();

            Console.WriteLine("This tool will generate a password reset code which you may use to reset a forgotten admin password for a Hikvision camera");

            HikvisionPassword hikvisionPassword = new HikvisionPassword();

            string serial_number = String.Empty;
            bool   serial_valid  = false;

            while (serial_valid == false)
            {
                Console.Write("Enter camera serial number: ");

                serial_number = Console.ReadLine();
                serial_valid  = hikvisionPassword.ValidateSerialNumber(serial_number);

                if (serial_valid == false)
                {
                    Console.WriteLine("Invalid serial number. Press Ctrl+C to abort.");
                }
            }

            string year       = String.Empty;
            bool   year_valid = false;

            while (year_valid == false)
            {
                Console.Write("Enter year displayed on screen: ");

                year       = Console.ReadLine();
                year_valid = hikvisionPassword.ValidateYear(year);

                if (year_valid == false)
                {
                    Console.WriteLine("Invalid year. Press Ctrl+C to abort.");
                }
            }

            string month      = String.Empty;
            bool   mont_valid = false;

            while (mont_valid == false)
            {
                Console.Write("Enter month displayed on screen: ");

                month      = Console.ReadLine();
                mont_valid = hikvisionPassword.ValidateMonth(month);

                if (mont_valid == false)
                {
                    Console.WriteLine("Invalid month. Press Ctrl+C to abort.");
                }
            }

            string day       = String.Empty;
            bool   day_valid = false;

            while (day_valid == false)
            {
                Console.Write("Enter day displayed on screen: ");

                day       = Console.ReadLine();
                day_valid = hikvisionPassword.ValidateDay(day);

                if (day_valid == false)
                {
                    Console.WriteLine("Invalid day. Press Ctrl+C to abort.");
                }
            }

            string reset_code = hikvisionPassword.GeneratePasswordResetCode(serial_number, year, month, day);

            Console.WriteLine(string.Format("Your password reset code is '{0}'", reset_code));

            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.Clear();

            Console.WriteLine("This tool will generate a password reset code which you may use to reset a forgotten admin password for a Hikvision camera");

            Console.WriteLine();

            HikvisionPassword hikvisionPassword = new HikvisionPassword();

            string exe_filename = Path.GetFileName(Assembly.GetEntryAssembly().Location);

            if (args.Length == 0)
            {
                Console.WriteLine(string.Format("usage: {0} [-h] [--serial SERIAL] [--year YEAR] [--month MONTH] [--day DAY]", exe_filename));
            }
            else
            {
                string serial_number = string.Empty;
                string year          = string.Empty;
                string month         = string.Empty;
                string day           = string.Empty;

                try
                {
                    string[] arg_names =
                    {
                        "serial", "s",
                        "year",   "y",
                        "month",  "m",
                        "day",    "d"
                    };

                    for (int i = 0; i < args.Length; i++)
                    {
                        string arg_name = args[i];

                        if (arg_name.StartsWith("--") == true || arg_name.StartsWith("-") == true)
                        {
                            arg_name = arg_name.ToLower().TrimStart('-');
                            string arg_value = args[i + 1];

                            if (arg_names.Contains(arg_name) == false)
                            {
                                continue;
                            }

                            if (arg_name == "serial" || arg_name == "s")
                            {
                                if (hikvisionPassword.ValidateSerialNumber(arg_value) == false)
                                {
                                    Console.WriteLine("Invalid serial number.");
                                }
                                else
                                {
                                    serial_number = arg_value;
                                }
                            }

                            if (arg_name == "year" || arg_name == "y")
                            {
                                if (hikvisionPassword.ValidateYear(arg_value) == false)
                                {
                                    Console.WriteLine("Invalid year.");
                                }
                                else
                                {
                                    year = arg_value;
                                }
                            }

                            if (arg_name == "month" || arg_name == "m")
                            {
                                if (hikvisionPassword.ValidateMonth(arg_value) == false)
                                {
                                    Console.WriteLine("Invalid month.");
                                }
                                else
                                {
                                    month = arg_value;
                                }
                            }

                            if (arg_name == "day" || arg_name == "d")
                            {
                                if (hikvisionPassword.ValidateDay(arg_value) == false)
                                {
                                    Console.WriteLine("Invalid day.");
                                }
                                else
                                {
                                    day = arg_value;
                                }
                            }
                        }
                    }
                }
                catch (Exception) { }

                string reset_code = hikvisionPassword.GeneratePasswordResetCode(serial_number, year, month, day);

                Console.WriteLine(string.Format("Your password reset code is '{0}'", reset_code));
            }

            Console.ReadKey();
        }