Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by StarlingSoftworksInteractive · Jan 18, 2017 at 08:41 AM · c#uiscript.

How to make one Inputfield Logon

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 alt text 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 alt text

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;    
     }
 }
     
 

screenshot-9.png (245.4 kB)
screenshot-10.png (216.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ForeignGod · Jan 18, 2017 at 09:06 AM

You should really rethink the way you want to handle the username and password. It is quite strange and not to mention it would be more of a hassle to make the password "hidden" in the input as your username.

Why don't you create a menu with only the logon inputs and a button that will enable the registration inputs and disable the logon ones.

If you absolutely need to have both username and password in the same input use the Split function and split at the space inbetween Username and pw.

 var input : String = "Username password123";
 var split : String[] = input.Split(" "[0]);

http://answers.unity3d.com/questions/218792/how-to-split-string.html https://forum.unity3d.com/threads/string-split-in-javascript.4969/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Click ui text to dissapear in 3D unity 2017 first person game script for ui multiple texts?,Clicking Text away in Unity 2017 3D first person game 0 Answers

How can i add a event onclick for a ui button that is child of canvas ? 1 Answer

How can i scale a ui Panel from the left side only ? 2 Answers

RectTransform position relative to Its Parent scale 1 Answer

Why when using a ui button script with ui toggle to interact with another script it's not working good ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges