Running python on server, executing commands from computer
Question: I made a login system with python. It works perfectly, but i want to run
script on server or web. For example: Steam. Steam wants username and password
to log in. So i wanted to do the same for my script. How can i do that?

My Code:

    
    
    import os
    import string
    import time
    
    version = "1.0 Alfa"
    
    def login():
        print ("----------------------------------------")
        print ("                Login                   ")
        print ("----------------------------------------")
        k_name = input("Enter username: ")
        if os.path.exists(k_name + ".txt") == False:
            print ("Username not found.")
            create()
        else:
            k_pass = input("Enter password: ")
            with open(k_name + ".txt", "r") as f:
                if k_pass == f.read():
                    print("Welcome %s!"%k_name)
                    f.close()
                    input()
                else:
                    print("Password is wrong!")
                    create()
    
    
    
    def create():
        print("You using login system %s" % version)
        print( "----------------------------------------")
        print("|                 Lobby                |")
        print( "----------------------------------------")
        starting = input("To create user type R, to login type L").upper()
        if starting == "R":
            name = input("Enter username: ")
            password = input("Enter password: ")
            password2 = input("Enter password again: ")
            if password == password2:
                newfile = open(name + ".txt", "w")
                newfile.write(password)
                newfile.close()
                print("User created. Redirecting you to login.")
                time.sleep(2)
                login()
            elif password != password2:
                print("Passwords doesn't match.")
                input()
                create()
        elif starting == "L":
            login()
        else:
            print("\nWrong button\n")
            create()
    
    create()
    


Answer: Here is the script which you can run : python test.py user pass it will save
data if file not found and perform login

    
    
    #!/usr/bin/env python
    import sys, getopt
    import os
    import time
    
    version = "1.0 Alfa"
    
    def login(username=None, password=None):
        print ("----------------------------------------")
        print ("                Login                   ")
        print ("----------------------------------------")
        if username:
            k_name = username
        else:
            k_name = input("Enter username: ")
        if os.path.exists(k_name + ".txt") == False:
            print ("Username not found.")
            create(username, password, "R")
        else:
            if password:
                k_pass = password
            else:
                k_pass = input("Enter password: ")
    
            with open(k_name + ".txt", "r") as f:
                if k_pass == f.read():
                    if not username:
                        print("Welcome %s!"%k_name)
                        f.close()
                        input()
                else:
                    print("Password is wrong!")
                    create()
    
    
    
    def create(username=None, password=None, mode="L"):
        print("You using login system %s" % version)
        print( "----------------------------------------")
        print("|                 Lobby                |")
        print( "----------------------------------------")
    
        if mode:
            starting = mode
        else:
            starting = input("To create user type R, to login type L").upper()
    
        if starting == "R":
            if username:
                name = username
            else:
                name = input("Enter username: ")
            if password:
                password2 = password
            else:
                password = input("Enter password: ")
                password2 = input("Enter password again: ")
    
            if password == password2:
                newfile = open(name + ".txt", "w")
                newfile.write(password)
                newfile.close()
                print("User created. Redirecting you to login.")
                time.sleep(2)
                login(username, password)
            elif password != password2:
                print("Passwords doesn't match.")
                input()
                create()
        elif starting == "L":
            login(username, password)
        else:
            print("\nWrong button\n")
            create()
    
    def main(argv):
        print sys.argv
    
        if len(sys.argv) < 3:
            print 'test.py <username> <password>'
            sys.exit()
    
        username = sys.argv[1]
        password = sys.argv[2]
    
        print 'username is ', username
        print 'password is ', password
        create(username, password)
    
    if __name__ == "__main__":
        main(sys.argv[1:])
    

