upd Authentification

This commit is contained in:
Daria
2021-10-20 06:09:18 +03:00
parent eab3081ec2
commit 72069508d2
24 changed files with 457 additions and 191 deletions

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SvetoforVKBot.Services
{
public class PasswordService
{
public static string GeneratePassword()
{
int length = 6;
StringBuilder password = new StringBuilder();
Random random = new Random();
while (password.Length < length)
{
int c = random.Next(0, 9);
password.Append(c);
}
return password.ToString();
}
public static string CreateMD5(string input)
{
// Use input string to calculate MD5 hash
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString().ToLower();
}
}
}
}