123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- using Avalonia.Controls;
- using ReactiveUI;
- using Captcha.Views;
- using System.Dynamic;
- using Tmds.DBus.Protocol;
- using System.Collections.Generic;
- using System.Security.Cryptography.X509Certificates;
- using Avalonia.Controls.Shapes;
- using Avalonia.Media;
- using Avalonia;
- using System;
- using System.Windows.Input;
- using Avalonia.Data;
- using Avalonia.Threading;
- using System.Threading;
- namespace Captcha.ViewModels
- {
- public class MainWindowViewModel : ViewModelBase
- {
- UserControl us = new Autorize();
- public UserControl US
- {
- get => us;
- set => this.RaiseAndSetIfChanged(ref us, value);
- }
- public CalculatorViewModel CalcVM { get => calcVM; set => calcVM = value; }
- CalculatorViewModel calcVM = new CalculatorViewModel();
- public void ToCalc()
- {
- US = new Calculator();
- }
- DispatcherTimer distimer = new DispatcherTimer();
- string login = "";
- string password = "";
- string capcha = "";
- string check;
- int count = 0;
- bool visa = true;
- bool visc = false;
- bool on = true;
- public string Login
- {
- get => login;
- set => this.RaiseAndSetIfChanged(ref login, value);
- }
- public string Password
- {
- get => password;
- set => this.RaiseAndSetIfChanged(ref password, value);
- }
- public string Capcha
- {
- get => capcha;
- set => this.RaiseAndSetIfChanged(ref capcha, value);
- }
- Canvas can;
- public Canvas Can
- {
- get => can;
- set => this.RaiseAndSetIfChanged(ref can, value);
- }
- public void CreateCaptcha() // метод для создания Canvas, внутри которого рандомно генерируются линии
- {
- SolidColorBrush color = new SolidColorBrush(Color.FromRgb(155, 155, 155));
- Canvas canvas = new Canvas()
- {
- Width = 210,
- Height = 100,
- Background = color
- };
- Random rnd = new Random();
- TextBlock text = new TextBlock()
- {
- Text = Convert.ToString(rnd.Next(0, 9)),
- FontSize = 36,
- Foreground = Brushes.Black,
- Padding = new Thickness(20)
- };
- TextBlock text1 = new TextBlock()
- {
- Text = Convert.ToString(Convert.ToChar(rnd.Next(97, 123))),
- FontSize = 36,
- Foreground = Brushes.Black,
- Padding = new Thickness(40)
- };
- TextBlock text2 = new TextBlock()
- {
- Text = Convert.ToString(rnd.Next(0, 20)),
- FontSize = 36,
- Foreground = Brushes.Black,
- Padding = new Thickness(60,10),
- };
- TextBlock text3 = new TextBlock()
- {
- Text = Convert.ToString(Convert.ToChar(rnd.Next(97, 123))),
- FontSize = 36,
- Foreground = Brushes.Black,
- Padding = new Thickness(100,2)
- };
- TextBlock text4 = new TextBlock()
- {
- Text = Convert.ToString(rnd.Next(0, 9)),
- FontSize = 36,
- Foreground = Brushes.Black,
- Padding = new Thickness(130,10)
- };
- TextBlock text5 = new TextBlock()
- {
- Text = Convert.ToString(Convert.ToChar(rnd.Next(65, 91))),
- FontSize = 36,
- Foreground = Brushes.Black,
- Padding = new Thickness(150,1)
- };
- TextBlock text6 = new TextBlock()
- {
- Text = Convert.ToString(Convert.ToChar(rnd.Next(97, 123))),
- FontSize = 36,
- Foreground = Brushes.Black,
- Padding = new Thickness(170,-3)
- };
- canvas.Children.Add(text);
- canvas.Children.Add(text1);
- canvas.Children.Add(text2);
- canvas.Children.Add(text3);
- canvas.Children.Add(text4);
- canvas.Children.Add(text5);
- canvas.Children.Add(text6);
- check = text.Text + text1.Text + text2.Text + text3.Text + text4.Text + text5.Text + text6.Text;
- for (int i = 0; i <= 10; i++)
- {
- Line line = new Line()
- {
- StartPoint = new Point(rnd.Next(220), rnd.Next(100)),
- EndPoint = new Point(rnd.Next(220), rnd.Next(100)),
- Stroke = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(0, 155)), Convert.ToByte(rnd.Next(0, 155)), Convert.ToByte(rnd.Next(0, 155)))),
- StrokeThickness = 2
- };
- canvas.Children.Add(line);
- }
- Can = canvas;
- }
- public bool VisibilityAuto
- {
- get => visa;
- set => this.RaiseAndSetIfChanged(ref visa, value);
- }
- public bool VisibilityCaptcha
- {
- get => visc;
- set => this.RaiseAndSetIfChanged(ref visc, value);
- }
- public bool Enabled
- {
- get => on;
- set => this.RaiseAndSetIfChanged(ref on, value);
- }
- public void Check()
- {
- if (Login != Models.UserClass.Login || Password != Models.UserClass.Login)
- {
- count+=1;
- }
- else
- {
- ToCalc();
- }
- if (count == 1)
- {
- VisibilityCaptcha = true;
- VisibilityAuto = false;
- CreateCaptcha();
-
- }
- }
- public void CheckCaptcha()
- {
- if (Capcha != check || Login != Models.UserClass.Login || Password != Models.UserClass.Login)
- {
- count++;
- }
- else
- {
- ToCalc();
- }
- if(count > 1)
- {
- Enabled = false;
- VisibilityCaptcha = false;
- Login = "";
- Password = "";
- Capcha = "";
- distimer.Interval = new TimeSpan(0, 0, 10);
- distimer.Tick += new EventHandler(TimerEnd);
- distimer.Start();
- }
- }
- public void TimerEnd(object sender, EventArgs e)
- {
- Enabled = true;
- CreateCaptcha();
- VisibilityCaptcha = true;
- distimer.Stop();
- }
- }
- }
|