using Microsoft.AspNetCore.Http; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace ProRestaurant.Classes { public class CommonFunctions { public static string GetHashSHA256(string text) { SHA256Managed crypt = new SHA256Managed(); string hash = string.Empty; byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(text), 0, Encoding.UTF8.GetByteCount(text)); foreach (byte bit in crypto) { hash += bit.ToString("x2"); } return hash; } public static string GenerateRandomPassword() { string values = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%_"; char[] chars = values.ToArray(); ArrayList used = new ArrayList(); string password = ""; while (password.Length < 10) { Random r = new Random(); int i = r.Next(0, values.Length); if (!used.Contains(chars[i].ToString())) { password += chars[i].ToString(); used.Add(chars[i].ToString()); } } return password; } } }