11from keyauth import api
22import os
3- import sys
43import os .path
5- import platform
64import hashlib
75from time import sleep
86from datetime import datetime
97
8+ #import json as jsond
9+ #^^ only for auto login/json writing/reading
10+
1011# watch setup video if you need help https://www.youtube.com/watch?v=L2eAQOmuUiA
1112os .system ("cls" )
1213os .system ("title Python Example" )
@@ -23,11 +24,11 @@ def getchecksum():
2324 return digest
2425
2526keyauthapp = api (
26- name = "" ,
27- ownerid = "" ,
28- secret = "" ,
29- version = "1.0" ,
30- hash_to_check = getchecksum ()
27+ name = "" , #App name (Manage Applications --> Application name)
28+ ownerid = "" , #Owner ID (Account-Settings --> OwnerID)
29+ secret = "" , #App secret(Manage Applications --> App credentials code)
30+ version = "1.0" ,
31+ hash_to_check = getchecksum ()
3132)
3233
3334print (f"""
@@ -66,7 +67,7 @@ def getchecksum():
6667 keyauthapp .license (key )
6768else :
6869 print ("\n Not Valid Option" )
69- sys . exit ( )
70+ os . _exit ( 1 )
7071
7172
7273#region Extra Functions
@@ -114,8 +115,121 @@ def getchecksum():
114115#* Send chat message
115116#keyauthapp.chatSend("MESSAGE", "CHANNEL")
116117
118+
119+ #* Auto-Login Example (THIS IS JUST AN EXAMPLE --> YOU WILL HAVE TO EDIT THE CODE PROBABLY)
120+ #1. Checking and Reading JSON
121+
122+ #### Note: Remove the ''' on line 124 and 183
123+
124+ '''try:
125+ if os.path.isfile('auth.json'): #Checking if the auth file exist
126+ if jsond.load(open("auth.json"))["authusername"] == "": #Checks if the authusername is empty or not
127+ print("""
128+ 1. Login
129+ 2. Register
130+ """)
131+ ans=input("Select Option: ") #Skipping auto-login bc auth file is empty
132+ if ans=="1":
133+ user = input('Provide username: ')
134+ password = input('Provide password: ')
135+ keyauthapp.login(user,password)
136+ elif ans=="2":
137+ user = input('Provide username: ')
138+ password = input('Provide password: ')
139+ license = input('Provide License: ')
140+ keyauthapp.register(user,password,license)
141+ else:
142+ print("\n Not Valid Option")
143+ os._exit(1)
144+ else:
145+ try: #2. Auto login
146+ with open('auth.json', 'r') as f:
147+ authfile = jsond.load(f)
148+ authuser = authfile.get('authusername')
149+ authpass = authfile.get('authpassword')
150+ keyauthapp.login(authuser,authpass)
151+ except Exception as e: #Error stuff
152+ print(e)
153+ else: #Creating auth file bc its missing
154+ try:
155+ f = open("auth.json", "a") #Writing content
156+ f.write("""{
157+ "authusername": "",
158+ "authpassword": ""
159+ }""")
160+ f.close()
161+ print ("""
162+ 1. Login
163+ 2. Register
164+ """)#Again skipping auto-login bc the file is empty/missing
165+ ans=input("Select Option: ")
166+ if ans=="1":
167+ user = input('Provide username: ')
168+ password = input('Provide password: ')
169+ keyauthapp.login(user,password)
170+ elif ans=="2":
171+ user = input('Provide username: ')
172+ password = input('Provide password: ')
173+ license = input('Provide License: ')
174+ keyauthapp.register(user,password,license)
175+ else:
176+ print("\n Not Valid Option")
177+ os._exit(1)
178+ except Exception as e: #Error stuff
179+ print(e)
180+ os._exit(1)
181+ except Exception as e: #Error stuff
182+ print(e)
183+ os._exit(1)'''
184+
185+
186+ #Writing user data on login:
187+ #Check Keyauth.py file --> Line 152
188+ #Replace the whole login function with this login function (This has auto user data dumping, so the user only have to login once)
189+ #Note: The auto login function above is needed for this bc it creates the auth file, if the auth file is missing this wont work
190+
191+ '''def login(self, user, password, hwid=None):
192+ self.checkinit()
193+ if hwid is None:
194+ hwid = others.get_hwid()
195+
196+ init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest()
197+
198+ post_data = {
199+ "type": binascii.hexlify(("login").encode()),
200+ "username": encryption.encrypt(user, self.enckey, init_iv),
201+ "pass": encryption.encrypt(password, self.enckey, init_iv),
202+ "hwid": encryption.encrypt(hwid, self.enckey, init_iv),
203+ "sessionid": binascii.hexlify(self.sessionid.encode()),
204+ "name": binascii.hexlify(self.name.encode()),
205+ "ownerid": binascii.hexlify(self.ownerid.encode()),
206+ "init_iv": init_iv
207+ }
208+
209+ response = self.__do_request(post_data)
210+
211+ response = encryption.decrypt(response, self.enckey, init_iv)
212+
213+ json = jsond.loads(response)
214+
215+ if json["success"]:
216+ self.__load_user_data(json["info"])
217+ if jsond.load(open("auth.json"))["authusername"] == "": #Check if the authusername is empty so it can write the user data
218+ authfile = jsond.load(open("Files/auth.json"))
219+ authfile["authusername"] = user #login(self, user)
220+ jsond.dump(authfile, open('Files/auth.json', 'w'), sort_keys=False, indent=4) #Dumping username to auth file/You can change the indent
221+ authfile["authpassword"] = password #login(self, password)
222+ jsond.dump(authfile, open('Files/auth.json', 'w'), sort_keys=False, indent=4) #Dumping password to auth file/You can change the indent
223+ else: #Auth file is filled with data so it skips the user data dumping
224+ pass
225+ print("successfully logged in")
226+ else:
227+ print(json["message"])
228+ os._exit(1)'''
229+
117230#endregion
118231
232+
119233print ("\n User data: " )
120234print ("Username: " + keyauthapp .user_data .username )
121235print ("IP address: " + keyauthapp .user_data .ip )
@@ -147,4 +261,4 @@ def getchecksum():
147261print (f"Current Session Validation Status: { keyauthapp .check ()} " )
148262print ("Exiting in 10 secs...." )
149263sleep (10 )
150- sys . exit ( 0 )
264+ os . _exit ( 1 )
0 commit comments