Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System.Xml;
  6. using System.IO;
  7.  
  8. public class LOGINTESTSCRIPT : MonoBehaviour
  9. {
  10.     private string currentUsername;
  11.     private string currentPassword;
  12.  
  13.     public InputField mainInputField;
  14.    
  15.     void Update()
  16.     {
  17.         if (Input.GetKeyDown(KeyCode.Space))
  18.         {
  19.             CreateLogin();
  20.         }
  21.     }
  22.  
  23.     public void CreateLogin()
  24.     {
  25.         currentUsername = transform.parent.GetChild(0).GetComponent<UsernameScript>().InputUsername();
  26.         currentPassword = transform.parent.GetChild(1).GetComponent<PasswordScript>().InputPassword();
  27.  
  28.         string filePath = Application.dataPath + "User1.xml";
  29.  
  30.         if (File.Exists(filePath))
  31.             File.Delete(filePath);
  32.         XmlDocument xmlDoc = new XmlDocument();
  33.         xmlDoc.LoadXml("<User ></User>");
  34.  
  35.         XmlElement root = xmlDoc.DocumentElement;
  36.         root.SetAttribute("name", currentUsername);
  37.        
  38.             XmlElement node = xmlDoc.CreateElement("Password");
  39.             node.SetAttribute("pass",currentPassword);
  40.             root.AppendChild(node);
  41.        
  42.         xmlDoc.Save("User1.xml");
  43.  
  44.  
  45.     }
  46.  
  47.     public void CheckUser ()
  48.     {
  49.         bool correctUsername = false;
  50.         bool correctPassword = false;
  51.  
  52.  
  53.         XmlReader reader = XmlReader.Create("C:\\Users\\Lotus\\Documents\\GitHub\\BarrenMusicFestival\\User1.xml");
  54.         while (reader.Read())
  55.         {
  56.             if (reader.Name == "User1")
  57.             {
  58.                 if (GameObject.Find("EnterUsernameInlog").GetComponent<UsernameScript>().InputUsername() == reader.GetAttribute("name"))
  59.                 {
  60.                     correctUsername = true;
  61.                 }
  62.  
  63.             }
  64.             if (reader.Name == "Password")
  65.             {
  66.                 if (GameObject.Find("EnterPasswordInlog").GetComponent<UsernameScript>().InputUsername() == reader.GetAttribute("pass"))
  67.                 {
  68.                     correctPassword = true;
  69.                 }
  70.             }
  71.             if (correctUsername && correctPassword)
  72.             {
  73.                 //do login thing
  74.  
  75.             }
  76.  
  77.         }
  78.     }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement