| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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/Questions.php?";
- public string categoriesURL = "http://nordh.xyz:8088/Categories.php";
- public Text statusText;
- List<Category> categories = new List<Category>();
- private void Awake()
- {
- StartCoroutine(getCategories());
- }
- private IEnumerator getCategories()
- {
- UnityWebRequest request = UnityWebRequest.Get(categoriesURL);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.Success)
- {
- 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');
- }
- }
|