Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CommonFunctions.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Microsoft.AspNetCore.Http;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Security.Cryptography;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace ProRestaurant.Classes
  10. {
  11. public class CommonFunctions
  12. {
  13. public static string GetHashSHA256(string text)
  14. {
  15. SHA256Managed crypt = new SHA256Managed();
  16. string hash = string.Empty;
  17. byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(text), 0, Encoding.UTF8.GetByteCount(text));
  18. foreach (byte bit in crypto)
  19. {
  20. hash += bit.ToString("x2");
  21. }
  22. return hash;
  23. }
  24. public static string GenerateRandomPassword()
  25. {
  26. string values = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%_";
  27. char[] chars = values.ToArray();
  28. ArrayList used = new ArrayList();
  29. string password = "";
  30. while (password.Length < 10)
  31. {
  32. Random r = new Random();
  33. int i = r.Next(0, values.Length);
  34. if (!used.Contains(chars[i].ToString()))
  35. {
  36. password += chars[i].ToString();
  37. used.Add(chars[i].ToString());
  38. }
  39. }
  40. return password;
  41. }
  42. }
  43. }