DatabaseController.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class DatabaseController : MonoBehaviour
  6. {
  7. private string secretKey = "TheNarKampenSecretKey";
  8. public string questionURL = "http://nordh.xyz/narKampen/Questions.php?";
  9. public string categoriesURL = "http://nordh.xyz/narKampen/Categories.php?";
  10. public Text statusText;
  11. public IEnumerator getQuestion()
  12. {
  13. Question question = new Question();
  14. WWW getQuestion = new WWW(questionURL);
  15. yield return getQuestion;
  16. if (getQuestion.error != null)
  17. {
  18. print("There was an error getting question: " + getQuestion.error);
  19. }
  20. else
  21. {
  22. statusText.text = getQuestion.text;
  23. }
  24. }
  25. public string Md5Sum(string strToEncrypt)
  26. {
  27. System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
  28. byte[] bytes = ue.GetBytes(strToEncrypt);
  29. // encrypt bytes
  30. System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
  31. byte[] hashBytes = md5.ComputeHash(bytes);
  32. // Convert the encrypted bytes back to a string (base 16)
  33. string hashString = "";
  34. for (int i = 0; i < hashBytes.Length; i++)
  35. {
  36. hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
  37. }
  38. return hashString.PadLeft(32, '0');
  39. }
  40. }