Hi Everyone, (sorry for a long post, couldn’t find the answer)
I have figure out how to create a Logon system which you can register or login in to the game. It does not use online servers and it save the file offline and check the password.
I have a problem the Logon system use 4 Input field
but I can’t figure out how to only use one input field for registration, to create a password and username and have another field for Login username and password , Hope you get what I mean, I provide some image such as this
Here is also my Scripts
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class Reg : MonoBehaviour {
public GameObject username;
public GameObject password;
private string UserName;
private string PassWord;
private string Container;
public void Registration(){
bool UN = false;
bool PWD = false;
if (UserName != "") { //not UserName not equal to space than perform this task
if (!System.IO.File.Exists (@"C:/" + username + ".txt")) {//if folder doesnt exist change UN to true
UN = true;
} else { //if file does exist print this
print ("Username is taken");
}
} else {//if field is empty print this
print ("Please create a Username");
}
if (PassWord != "") {
if (PassWord.Length > 4) {
PWD = true;
} else {
print ("Not enough character it need to be 6 or more");
}
} else {
print ("Please create a Password");
}
if (UN == true && PWD == true) {
bool Clear = true;
int i = 1;
foreach (char c in PassWord) {
if (Clear) {
PassWord = "";
Clear = false;
}
i++;
char Encrypted = (char)(c * i);
PassWord += Encrypted.ToString ();
}
Container = (UserName + Environment.NewLine + PassWord);
System.IO.File.WriteAllText (@"C:/Programs/" + UserName + ".txt", Container);
username.GetComponent<InputField> ().text = "";
password.GetComponent<InputField> ().text = "";
print ("Registration Complete");
}
}
void Update () {
if (Input.GetKeyDown(KeyCode.Return)){
if (PassWord != ""/*&&Email != ""&&Password != ""/*&&ConfPassword != ""*/){
Registration();
}
}
UserName = username.GetComponent<InputField>().text;
//Email = email.GetComponent<InputField>().text;
PassWord = password.GetComponent<InputField>().text;
//ConfPassword = confPassword.GetComponent<InputField>().text;
}
}
//Logon Script
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Text.RegularExpressions;
public class Logon : MonoBehaviour {
public GameObject username;
public GameObject password;
private string UserName;
private string PassWord;
private String[] Lines;
private string DecryptedPass;
public void LoginButton(){
bool UN = false;
bool PWD = false;
if (UserName != ""){
if(System.IO.File.Exists(@"C:/Programs/"+UserName+".txt")){
UN = true;
Lines = System.IO.File.ReadAllLines(@"C:/Programs/"+UserName+".txt");
} else {
Debug.LogWarning("UserName Incorrect");
}
} else {
Debug.LogWarning("Please Reg");
}
if (PassWord != ""){
if (System.IO.File.Exists(@"C:/Programs/"+UserName+".txt")){
int i = 1;
foreach(char c in Lines[1]){
i++;
char Decrypted = (char)(c / i);
DecryptedPass += Decrypted.ToString();
}
if (PassWord == DecryptedPass){
PWD = true;
}
} else {
Debug.LogWarning("Password Is invalid");
}
} else {
Debug.LogWarning("Password Field Empty");
}
if (UN == true&&PWD == true){
username.GetComponent<InputField>().text = "";
password.GetComponent<InputField>().text = "";
print ("Login Sucessful");
Application.LoadLevel("Start Menu");
}
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Tab)){
if (username.GetComponent<InputField>().isFocused){
password.GetComponent<InputField>().Select();
}
}
if (Input.GetKeyDown(KeyCode.Return)){
if (PassWord != ""&&PassWord != ""){
LoginButton();
}
}
UserName = username.GetComponent<InputField>().text;
PassWord = password.GetComponent<InputField>().text;
}
}