signinlca

signinlca

script to signin for volunteers at lca2015!

The script asks for input of firstname, lastname, tshirt size, amount of coffee volc and comments. It creates a python dict with this data along with the current date and hour. It gets the username of user and saves the data in the users home dir under the folder signinlca. It saves the data as a json object. Currently saves the file as firstname + lastname.

How could this be improved?

Signup/Signin System.

For signup - username, firstname, lastname, password(x2) is collected with input. Password is salted and hashed. Username, firstname, lastname, and password (salt/hash) is added to a dict. Dict is converted to a json object. json object is saved as a json file in the folder signinlca / USERNAME-FOLDER / .signup.json

For signin. Username is collected with input. Looks for folder of username. Opens .signup.json file - parsing data. Save the value of 'password' as a varible.

Asks for password (getpass.getpass('Password please: ') salt/hash this password. save password attempt if error, otherwise true complete signin.

TODO

add option to choose to login or logout. Y/N option for each one.

add logout script that appends to the login data. saves, time/date/comment. anything else?

Asign to jobs/room?

Graph up total hour worked in day/week

scp/rsync data to server/web page.

Make new account, use existing account.

Database of existing accounts... static page of files.

Add password to account

If you signin, doesn't ask if want to sign out.

If you signout, doesn't ask if you want to sign in.

Hash passwords

When creating account asked for username (which could be firstname + lastname), and password. Passwords are hashed and when user tries to login the password inputed is compared to the hashed password.

Save that hash as a varible that is then complared with the saved hash password.

I have their signin data. Now what to do with it? Save it as a json object to be then used when they signin later?

More security on it? Hash their usernames, firstnames, 2nd password?

In [52]:
import os
#import time
import json
import getpass
import arrow
import hashlib
from passlib.hash import pbkdf2_sha256
from walkdir import filtered_walk, dir_paths, all_paths, file_paths
In [53]:
gmtz = arrow.utcnow()
In [54]:
yrmt = gmtz.strftime("%Y")
mthza = gmtz.strftime("%m")
dthaq = gmtz.strftime("%d")
gmtz.strftime("%Y")
#yearz = strftime("%y", gmtime())
#monthz = strftime("%m", gmtime())
#dayz = strftime("%d", gmtime())
Out[54]:
'2015'
In [55]:
yrmt
Out[55]:
'2015'
In [56]:
mthza
Out[56]:
'02'
In [57]:
dthaq
Out[57]:
'16'
In [58]:
def returndate():
    return (dthaq + '-' + mthza + '-' + yrmt)

def returntime():
    return gmtz.strftime('%H:%M:%S')

puser = ('wcmckee')

yrnum = gmtz.strftime("%Y")
mnthnum = gmtz.strftime("%m")
dayzum = gmtz.strftime("%d")

signpath = ('/home/' + puser + '/signinlca')
yrpath = (signpath + '/' + yrnum)
mnthpath = (yrpath + '/' + mnthnum)
dayzpath = (mnthpath + '/' + dayzum)
In [59]:
if os.path.isdir(signpath) == True:
    print 'Path is there'
else:
    print 'Path not there'
    os.mkdir(signpath)
Path is there
In [60]:
if os.path.isdir(yrpath) == True:
    print 'Year Path is there'
else:
    print 'Year Path not there'
    os.mkdir(yrpath)
    
if os.path.isdir(mnthpath) == True:
    print 'Month Path is there'
else:
    print 'Month Path not there'
    os.mkdir(mnthpath)
    
if os.path.isdir(dayzpath) == True:
    print 'Day Path is there'
else:
    print 'Day Path not there'
    os.mkdir(dayzpath)
Year Path is there
Month Path is there
Day Path is there
In [61]:
dayzpath
Out[61]:
'/home/wcmckee/signinlca/2015/02/16'
In [62]:
os.chdir(dayzpath)
In [63]:
opsign = open('/home/wcmckee/signinlca/index.json', 'w')
In [77]:
signup = raw_input('signup y/n ')
signupd = dict()

numchez = 0

if 'y' in signup:
    print('Welcome to signup!')
    firnam = raw_input('firstname: ')
    signupd.update({"firstname":firnam, })
    lasnam = raw_input('last name: ')
    
    usenam = raw_input('username: ')
    emnam = raw_input('email: ')
    
    
    os.mkdir('/home/wcmckee/signinlca/usernames/' + usenam) 
    #passworz = passwd()
    
    pastest = getpass.getpass('password: ')

    pasnde = getpass.getpass('enter password again: ')
    
    signupd.update({"firstname":firnam, "lastname":lasnam,
                "username":usenam})
    
    hashez = pbkdf2_sha256.encrypt(pastest, rounds=200000, salt_size=16)
    emhash = pbkdf2_sha256.encrypt(emnam, rounds=200000, salt_size=16)
    
    signupd.update({"password":hashez, "email":emhash})
    
    savjsn = open('/home/wcmckee/signinlca/usernames/' + usenam + '/.signups.json', 'a')
    jsncov = json.dumps(signupd)
    savjsn.write(jsncov)
    savjsn.close()
    usdir = ('useradd -p ' + pastest + ' ' + usenam)
    os.system(usdir)
    print('Signup Complete. You can now signin with the username and password')

for logy in range(12):
    ferzr = (numchez)
    numchez = (numchez + 10)
    #usfaz = ('/home/wcmckee/signinlca/usernames/' + str(numchez) + usenam + '/index.json', 'w')
    os.mkdir('/home/wcmckee/signinlca/usernames/' + str(usenam) + '/' + str(logy))
signup y/n y
Welcome to signup!
firstname: will
last name: mckee
username: figlet
email: will@test.com
password: ········
enter password again: ········
Signup Complete. You can now signin with the username and password
In [65]:
#hashez = pbkdf2_sha256.encrypt(pastest, rounds=200000, salt_size=16)
#signupd.update({"password":hashez})
#signin. need to open 
print ('signin!')
loginam = raw_input('Username: ')
#Open logins.json, find the username json object
loginpas = getpass.getpass('Password: ')
vercryp = pbkdf2_sha256.verify(loginpas, hashez)
if vercryp == True:
    print 'passwords correct - Logged in!'
    
else:
    print 'passwords wrong - Could not log!'
    #exit
signin!
Username: point
Password: ········
passwords correct - Logged in!
In [66]:
type(signupd)
Out[66]:
dict
In [66]:
 
In [67]:
#savjsn.write(jsncov)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-67-a899169d95c8> in <module>()
----> 1 savjsn.write(jsncov)

ValueError: I/O operation on closed file
In [17]:
#savjsn.close()
In [19]:
dicsigni = dict()
In [21]:
signin = raw_input('signin? y/n')

if 'y' in signin:
    #uzname = raw_input('firstname: ')
    #lzname = raw_input('lastname: ')
    uzernam = raw_input('username: ')
    
    dicsigni.update({'username': uzernam})
    opsignin = open('/home/wcmckee/signinlca/usernames/' + str(uzernam) + ('/') + ('.signin.json'), 'w') 

    logtest = getpass.getpass('login password: ')
    loghash = pbkdf2_sha256.encrypt(logtest, rounds=200000, salt_size=16)
    vercryp = pbkdf2_sha256.verify(logtest, hashez)
    dicsigni.update({'password':loghash})
                    
    dicjsn = json.dumps(dicsigni)
    
    opsignin.write(dicjsn)
    opsignin.close()
    
                    
    #opsignin.write

    if pastest == True:
        print 'passwords correct'
signin? y/ny
username: wcm
login password: ········
In [24]:
ersignin = open('/home/wcmckee/signinlca/usernames/' + str(uzernam) + ('/') + ('.signin.json'), 'r') 

paswz = ersignin.read()
In [28]:
dicvert = json.loads(paswz)
In [49]:
dicloin = dicvert['password']
In [39]:
tresignin = open('/home/wcmckee/signinlca/usernames/' + str(uzernam) + ('/') + ('.signups.json'), 'r')
In [40]:
convea =  tresignin.read()
In [43]:
jsnver = json.loads(convea)
In [47]:
jpas = jsnver['password']
In [50]:
jpas
Out[50]:
u'$pbkdf2-sha256$200000$utc6h9A6B.CcsxZirHVurQ$rHAHVhTN5pwOgBTj.6un2605pM.xZ8Kbu7wYRqPcFGo'
In [51]:
dicloin
Out[51]:
u'$pbkdf2-sha256$200000$tTZmrJVyTinFmHPOWYtxjg$esTV1MEbmqXDIxc4ZHUFdThYpTZdk3.2101Ndga0mes'
In [118]:
loginz = raw_input('signin y/n ')
if 'y' in loginz:
    print('You signed in')
    #logoutz = None
else:
    logoutz = raw_input('signouts y/n ')
signin y/n y
You signed in
In [119]:
if 'y' in loginz:
    firnam = raw_input('first name: ')
    lasnam = raw_input('last name: ')
    tshir = raw_input('tshirt size: ')
    cofvol = raw_input('coffee volc: ')
    comen = raw_input('comments: ')
    betdict = dict()
    betdict.update({'first-name' : firnam, 'last-name' : lasnam, 'signin-date' : returndate()})
    betdict.update({'signin-hrmin' : returntime()})
    betdict.update({'tshirt-size' : tshir})
    betdict.update({'coffees' : int(cofvol)})
    betdict.update({'comments:' : comen})
    convj = json.dumps(betdict)
    puser = getpass.getuser()
    opday = open((dayzpath + '/' + firnam + lasnam) + '.json', 'w')
    opday.write(str(convj))
    opday.close()
else:
    print ('not signing in')
first name: w
last name: mcke
tshirt size: L
coffee volc: 4
comments: test
In [480]:
if 'y' in logoutz:
    comout = raw_input('out comments: ')
    outdic = dict()
    
    firnaz = raw_input('first name: ' )
    lasnaz = raw_input('last name: ')
    outdic.update({'signout-date': returndate()})
    outdic.update({'signout-time': returntime()})
    outdic.update({'signout-comment': comout})
    conout = json.dumps(outdic)
    signoutz = open((dayzpath + '/' + firnaz + lasnaz) + '.json', 'a')
    signoutz.write(str(conout))
    signoutz.close()
else:
    print ('not signing out')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-480-427a1c2429f6> in <module>()
----> 1 if 'y' in logoutz:
      2     comout = raw_input('out comments: ')
      3     outdic = dict()
      4 
      5     firnaz = raw_input('first name: ' )

TypeError: argument of type 'NoneType' is not iterable
In [481]:
os.listdir(dayzpath)
Out[481]:
['williammckee.json', 'helentesting.json']
In [481]:
 
In [68]:
files = file_paths(filtered_walk('/home/wcmckee/signinlca/', depth=100, included_files=['*.json']))
In [69]:
for fie in files:
    #print fie
    print fie
/home/wcmckee/signinlca/index.json
/home/wcmckee/signinlca/signups.json
/home/wcmckee/signinlca/2015/02/15/williammckee.json
/home/wcmckee/signinlca/2015/02/15/holleymckee.json
/home/wcmckee/signinlca/2015/02/15/wmcke.json
/home/wcmckee/signinlca/2015/Feb/07/williammckee.json
/home/wcmckee/signinlca/2015/Feb/07/blahmc.json
/home/wcmckee/signinlca/2015/Feb/13/williammckee.json
/home/wcmckee/signinlca/2015/Feb/15/williammckee.json
/home/wcmckee/signinlca/2015/Feb/14/willmckee.json
/home/wcmckee/signinlca/usernames/wcm/.signups.json
/home/wcmckee/signinlca/usernames/wcm/.signin.json
/home/wcmckee/signinlca/usernames/wmen/.signups.json
/home/wcmckee/signinlca/usernames/webmck/.signups.json
/home/wcmckee/signinlca/usernames/pjohns/.signups.json
/home/wcmckee/signinlca/usernames/checkthis/.signups.json
/home/wcmckee/signinlca/usernames/jchick/.signups.json
/home/wcmckee/signinlca/usernames/poi/.signups.json
/home/wcmckee/signinlca/usernames/qwe/.signups.json
/home/wcmckee/signinlca/usernames/point/.signups.json
/home/wcmckee/signinlca/usernames/cvb/.signups.json
/home/wcmckee/signinlca/usernames/gerty/.signups.json
/home/wcmckee/signinlca/usernames/gerty/.signin.json
/home/wcmckee/signinlca/usernames/jblog/.signups.json
/home/wcmckee/signinlca/usernames/ssung/.signups.json
/home/wcmckee/signinlca/usernames/clittle/.signups.json
In [72]:
uslis = os.listdir('/home/wcmckee/signinlca/usernames/')
In [74]:
print ('User List: ')
for usl in uslis:
    print usl
User List: 
wcm
wmck
wmen
webmck
pjohns
checkthis
jchick
poi
qwe
point
cvb
gerty
jblog
ssung
clittle
In [ ]:
 

Comments

Comments powered by Disqus