using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; public class DatabaseController : MonoBehaviour { private string secretKey = "TheNarKampenSecretKey"; public string questionURL = "http://nordh.xyz:8088/narKampen/Questions.php?"; public string categoriesURL = "http://nordh.xyz:8088/narKampen/Categories.php"; public Text statusText; List categories = new List(); private void Awake() { StartCoroutine(getCategories()); } private IEnumerator getCategories() { UnityWebRequest request = UnityWebRequest.Get(categoriesURL); yield return request.SendWebRequest(); if (request.isDone) { Debug.Log(request.downloadHandler.text); } else if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.DataProcessingError) { Debug.Log("ERROR " + request.downloadHandler.error); } } public IEnumerator getQuestion() { Question question = new Question(); WWW getQuestion = new WWW(questionURL); yield return getQuestion; if (getQuestion.error != null) { print("There was an error getting question: " + getQuestion.error); } else { statusText.text = getQuestion.text; } } public string Md5Sum(string strToEncrypt) { System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding(); byte[] bytes = ue.GetBytes(strToEncrypt); // encrypt bytes System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] hashBytes = md5.ComputeHash(bytes); // Convert the encrypted bytes back to a string (base 16) string hashString = ""; for (int i = 0; i < hashBytes.Length; i++) { hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0'); } return hashString.PadLeft(32, '0'); } }