Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System.Xml;
- using System.IO;
- public class LOGINTESTSCRIPT : MonoBehaviour
- {
- private string currentUsername;
- private string currentPassword;
- public InputField mainInputField;
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- CreateLogin();
- }
- }
- public void CreateLogin()
- {
- currentUsername = transform.parent.GetChild(0).GetComponent<UsernameScript>().InputUsername();
- currentPassword = transform.parent.GetChild(1).GetComponent<PasswordScript>().InputPassword();
- string filePath = Application.dataPath + "User1.xml";
- if (File.Exists(filePath))
- File.Delete(filePath);
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.LoadXml("<User ></User>");
- XmlElement root = xmlDoc.DocumentElement;
- root.SetAttribute("name", currentUsername);
- XmlElement node = xmlDoc.CreateElement("Password");
- node.SetAttribute("pass",currentPassword);
- root.AppendChild(node);
- xmlDoc.Save("User1.xml");
- }
- public void CheckUser ()
- {
- bool correctUsername = false;
- bool correctPassword = false;
- XmlReader reader = XmlReader.Create("C:\\Users\\Lotus\\Documents\\GitHub\\BarrenMusicFestival\\User1.xml");
- while (reader.Read())
- {
- if (reader.Name == "User1")
- {
- if (GameObject.Find("EnterUsernameInlog").GetComponent<UsernameScript>().InputUsername() == reader.GetAttribute("name"))
- {
- correctUsername = true;
- }
- }
- if (reader.Name == "Password")
- {
- if (GameObject.Find("EnterPasswordInlog").GetComponent<UsernameScript>().InputUsername() == reader.GetAttribute("pass"))
- {
- correctPassword = true;
- }
- }
- if (correctUsername && correctPassword)
- {
- //do login thing
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement