| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/usr/bin/env python2
-
- import xmlrpc.client
- import hashlib
- import os
- import sys
-
- # connects to the XMLRPC Server
- s = xmlrpc.client.ServerProxy('http://localhost:8000')
- clear = lambda: os.system('clear')
- # initalized the login process
- session, key = s.init()
- authenticated = False
- username = ''
- password = ''
-
- # concatenates the password and key and returns the hash
- def hash_pass( password, key ):
- return hashlib.sha256( ( password + key ).encode( 'utf-8' ) ).hexdigest()
-
- # starts main loop
- while True:
- clear()
- # if authenticated offer to user premium methods
- if authenticated:
- print( 'Welcome ' + username )
- print( 'Please enter what you want to do ( hello, create_user, logout )' )
- i = input().lower()
- clear()
- if ( i == 'hello' ):
- print( s.hello( session ) )
- elif ( i == 'create_user' ):
- print( 'Username: ' )
- un = input()
- clear()
- print( 'Password:' )
- pw = input()
- clear()
- print( s.create_user( session, un, pw ) )
- elif( i == 'logout' or i == 'exit' ):
- if ( s.logout( session, username, hash_pass( password, key ) ) ):
- authenticated = False
- sys.exit()
-
- else:
- print( 'Unknown action ' + i )
- print( 'Press any key to continue' )
- input();
- # otherwise offer to authenticate
- else:
- print( 'Username: ' )
- username = input()
- clear()
- print( 'Password:' )
- password = input()
- clear()
- authenticated = s.auth( session, username, hash_pass( password, key ) )
- pass
|