123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using AuthAndCaptcha.Models;
- using Avalonia.Controls;
- using Avalonia.Controls.Shapes;
- using Avalonia.Media;
- using ReactiveUI;
- namespace AuthAndCaptcha.ViewModels
- {
- public class AuthViewModel : ReactiveObject
- {
- string usersLogin;
- string usersPassword;
- string canText;
- string canTextTrue;
- bool authButtonVisible = true;
- bool canTextVisible = false;
- public string UsersLogin { get => usersLogin; set => this.RaiseAndSetIfChanged(ref usersLogin, value); }
- public string UsersPassword { get => usersPassword; set => this.RaiseAndSetIfChanged(ref usersPassword, value); }
- public string CanText { get => canText; set => this.RaiseAndSetIfChanged(ref canText, value); }
- public string CanTextTrue { get => canTextTrue; set => this.RaiseAndSetIfChanged(ref canTextTrue, value); }
- public bool AuthButtonVisible { get => authButtonVisible; set => this.RaiseAndSetIfChanged(ref authButtonVisible, value); }
- public bool CanTextVisible { get => canTextVisible; set => this.RaiseAndSetIfChanged(ref canTextVisible, value); }
- Canvas can;
- public Canvas Can { get => can; set => this.RaiseAndSetIfChanged(ref can, value); }
- public void CreateCaptcha()
- {
- Random rnd = new Random();
- SolidColorBrush color = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255))));
- FontStyle[] fontStyles = new FontStyle[2] { FontStyle.Normal, FontStyle.Italic };
- FontWeight[] fontWeights = new FontWeight[2] { FontWeight.Normal, FontWeight.Bold };
- int dist = 10;
- Canvas canvas = new Canvas()
- {
- Width = 400,
- Height = 400,
- Background = color
- };
- int len = rnd.Next(7, 10);
- for (int i = 0; i < 20; i++)
- {
- SolidColorBrush colorLine = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255))));
- Line line = new Line()
- {
- StartPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
- EndPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
- Stroke = colorLine,
- StrokeThickness = 3,
-
- };
- canvas.Children.Add(line);
- }
- for (int i = 0; i < len; i++)
- {
- FontStyle randomFontStyle = (FontStyle)rnd.Next(0, 3);
- string sym;
- int k = rnd.Next(0,2);
- if (k==0)
- {
- sym = Convert.ToString((char)rnd.Next(48, 57));
- }
- else
- {
- sym = Convert.ToString((char)rnd.Next(65, 90));
- }
- TextBlock text = new TextBlock()
- {
- Text = sym,
- FontSize = 20,
- Foreground = Brushes.Black,
- Margin = new Avalonia.Thickness(dist, rnd.Next(300), rnd.Next(300), 0),
- FontStyle = fontStyles[rnd.Next(0, 2)],
- FontWeight = fontWeights[rnd.Next(0, 2)]
- };
- canTextTrue = canTextTrue + Convert.ToString(text.Text);
- canvas.Children.Add(text);
- dist = dist + 35;
- }
- Debug.WriteLine(canTextTrue);
- Can = canvas;
- }
- }
- }
|