Saving input field in unity3d

I have developed an app for a book. When the app starts user needs to enter the code which is given inside of the book. If the code matches then the user will be promoted to the next scene. Everything is working fine. But I want to save the Code/Password that user had entered when he/she opened the app first time. So whenever the user opens the app again the application shouldn’t ask for the password again.

Code is given any help would be appreciated.

 using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    
    public class CheckKey : MonoBehaviour
    {
    	public InputField iField;
    	public string myName;
    	public string myText;
    
    	public GameObject MainScreen;
    	public GameObject Error;
    	public GameObject HideLogin;
    
        public void MyFunction()
    	{
    		//Debug.Log(iField.text);
    		myName = iField.text;
    		
    		if (myName == "kcgs2020")
    		{
    			MainScreen.SetActive(true);
    			HideLogin.SetActive(false);
    			
    		}
    
    		if (myName == "bc2020")
    		{
    			MainScreen.SetActive(true);
    			HideLogin.SetActive(false);
    		
    		}
    
    		else
    		{
    			Error.SetActive(true);
    		}
    	}
    }

You should do this with a binary formatter:

using UnityEngine;
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

    public static class StorageSystem
    {
        public static void SaveData<T>( T _data, string _fileName )
        {
            string _path = Application.persistentDataPath + _fileName;
            BinaryFormatter _formatter = new BinaryFormatter();
            FileStream _stream = new FileStream( _path, FileMode.Create );

            _formatter.Serialize( _stream, _data );
            _stream.Close();
        }

        public static BookData LoadBook()
        {
            string _path = Application.persistentDataPath + "/book.data";
            
            if( File.Exists( _path ) )
            {
                FileStream _stream = new FileStream( _path, FileMode.Open );
                BinaryFormatter _formatter = new BinaryFormatter();

                PlayerData _data = _formatter.Deserialize( _stream ) as BookData;
                _stream.Close();

                return _data;
            }
            else
            {
                Debug.LogError("Save file not found in " + _path);
                return null;
            }
        }
    }

That assumes you have a data container called BookData ie:

public class BookData
{
    public string title;
    public string autor;
    public string code;
    public bool codeMatch;
}

Then each time the app is open, you have check that file to see if the code matches and if no file exists, it means it hasn’t been created, so create one:

using UnityEngine;
     using System.Collections;
     using UnityEngine.UI;
     
     public class CheckKey : MonoBehaviour
     {
         public InputField iField;
         public string myName;
         public string myText;
         private BookData myBook;
     
         public GameObject MainScreen;
         public GameObject Error;
         public GameObject HideLogin;
     
         public void MyFunction()
         {
             //Debug.Log(iField.text);
             myName = iField.text;
             myBook = StorageSystem.LoadBook();

            if( myBook == null )
            {
                  myBook = new BookData();
                  myBook.title = “The Hobbit”;
                  myBook.author = “JRT”;
                  myBook.code = “kcgs2020”;
                  myBook.codeMatch = false;
             }

             if( !myBook.codeMatch )
             {
             
                 if (myName == "kcgs2020")
                 {
                     MainScreen.SetActive(true);
                     HideLogin.SetActive(false);
                     myBook.codeMatch = true;
                 }
     
                 if (myName == "bc2020")
                 {
                     MainScreen.SetActive(true);
                     HideLogin.SetActive(false);
             
                 }
     
                 else
                 {
                     Error.SetActive(true);
                 }
             }
             else
             {
                   //Books code was already matched
             }
         }
     }

This is obviously not an exact workable solution as I just have one book and it seems you have 2, but you can change it to do what you need.

Hope that helps