|
@@ -6,6 +6,8 @@ using UnityEngine.UI;
|
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.EventSystems;
|
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.SceneManagement;
|
|
|
using System;
|
|
using System;
|
|
|
|
|
+using System.Security.Cryptography;
|
|
|
|
|
+using System.Text;
|
|
|
|
|
|
|
|
public class Login : MonoBehaviour {
|
|
public class Login : MonoBehaviour {
|
|
|
|
|
|
|
@@ -88,14 +90,24 @@ public class Login : MonoBehaviour {
|
|
|
User u = new User();
|
|
User u = new User();
|
|
|
JsonUtility.FromJsonOverwrite(result, u);
|
|
JsonUtility.FromJsonOverwrite(result, u);
|
|
|
|
|
|
|
|
- if (int.TryParse(www.downloadHandler.text, out int userId)) {
|
|
|
|
|
- errorColor.a = 0;
|
|
|
|
|
- errorText.color = errorColor;
|
|
|
|
|
- PlayerPrefs.SetInt("UserId", userId);
|
|
|
|
|
- // load next scene
|
|
|
|
|
- SceneManager.LoadScene("MainMenu");
|
|
|
|
|
|
|
+ if (!u.userId.Equals("")) {
|
|
|
|
|
+ byte[] pwd = Encoding.UTF8.GetBytes(u.salt + Password);
|
|
|
|
|
+ SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
|
|
|
|
|
+ string pass = sha1.ComputeHash(pwd).ToString();
|
|
|
|
|
+ if (pass.Equals(u.pass)) {
|
|
|
|
|
+ errorColor.a = 0;
|
|
|
|
|
+ errorText.color = errorColor;
|
|
|
|
|
+ Int32.TryParse(u.userId, out int userId);
|
|
|
|
|
+ PlayerPrefs.SetInt("UserId", userId);
|
|
|
|
|
+ // load next scene
|
|
|
|
|
+ SceneManager.LoadScene("MainMenu");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ errorText.text = "Felaktig användare/lösenord";
|
|
|
|
|
+ errorColor.a = 1;
|
|
|
|
|
+ errorText.color = errorColor;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- errorText.text = "Misslyckades med inloggning";
|
|
|
|
|
|
|
+ errorText.text = "Användaren hittades inte";
|
|
|
errorColor.a = 1;
|
|
errorColor.a = 1;
|
|
|
errorText.color = errorColor;
|
|
errorText.color = errorColor;
|
|
|
}
|
|
}
|