Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
incomplete registration
#1
I know you guys have seen me post questions on registration programs... This is, I have not completed one that I actually like. It will be the start of creating a website / video game / anything I decide to program. Registration and login is important riiiiiiight.... so I just wanted to say I think because of the help from some of the classmates in CS50 and the folks on this forum I have come a long way in just a few months. I have not been programming very long at all... maybe a few months. I know this code is not as efficient as it could be but here we have the start of a registration form that I may stick with because I believe it's coming along pretty well for a newbie. If anyone has any suggestions I'd love the constructive crit. or of course if you just want something to do I will post on git if you request. I still need to add conditions to username and password to make sure special characters aren't used and length is appropriate, etc, still a lot of work to do buuuuuuuuuutttttt here goes nothing:

#!/usr/bin/env python3
import json
import time
import sys

def get_username():
    prompt_username = 'What is the username you wish to create?'
    username = input(prompt_username + '\n')
    return username
    
def get_password():
    prompt_password = 'Create a password'
    password = input(prompt_password + '\n')
    return password
    
    
def create_newUserList(username, password):
    userList = []
    userList.append(username)
    userList.append(password)
    return userList
    
def make_newUserDict(userList):
    convert = userList
    userDict = {}
    userDict[convert[0]] = convert[1]
    return userDict

def get_userDataDict():    
    filename = 'userdata.json'
    try:
        with open(filename) as f_obj:
            userdata = json.load(f_obj)
    except FileNotFoundError:
        return None
    else:
        return userdata
        
def create_userdataFile(userDict):
    filename = 'userdata.json'
    with open(filename, 'w') as f_obj:
        json.dump(userDict, f_obj)

def check_new_old(username, existing_usernames):
    new_username = username
    old_usernames = existing_usernames
    
    for k in old_usernames.keys():
        if new_username[0].lower() == k.lower():
            print('Username taken, prompting for new entry.')
            return None
        else:
            print('Username available.')
            return new_username

def add_goodUserInfo(good_userInfo, existing_userData):
    data_to_add = good_userInfo
    existing_data = existing_userData
    existing_data[data_to_add[0]] = data_to_add[1]
    
    filename = 'userdata.json'
    with open(filename, 'w') as f_obj:
        json.dump(existing_data, f_obj)

def main():
    
    while True:
        username = get_username()
        password = get_password()
        userList = create_newUserList(username, password)
        userDict = make_newUserDict(userList)
        existing_userData = get_userDataDict()
        
        if existing_userData:
            good_userInfo = check_new_old(userList, existing_userData)
            if good_userInfo:
                print('Adding username ' + good_userInfo[0] +
                ' to our system.')
                time.sleep(5)
                add_goodUserInfo(good_userInfo, existing_userData)
                print('Welcome, ' + good_userInfo[0] + '!')
                break
            else:
                print('Reprompt')
                continue
        else:
            create_userdataFile(userDict)
            break
    
    
main()
This isn't really asking for help unless you'd just like to help out... But more just claiming a happy coders feelings through accomplishment. ;-) Lets chat on it a bit Mr. Experienced, I'd love to learn more! Feed me knowledge! In advance I thank you!
Reply


Messages In This Thread
incomplete registration - by Low_Ki_ - May-12-2017, 12:08 AM
RE: incomplete registration - by Low_Ki_ - May-12-2017, 03:43 PM
RE: incomplete registration - by nilamo - May-12-2017, 04:00 PM
RE: incomplete registration - by Low_Ki_ - May-12-2017, 04:12 PM
RE: incomplete registration - by nilamo - May-12-2017, 04:57 PM
RE: incomplete registration - by Low_Ki_ - May-12-2017, 05:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Keep getting "SyntaxError: incomplete input" but can't see why. Pedroski55 2 269 May-08-2024, 06:40 AM
Last Post: Pedroski55
  Incomplete Output oldcity 6 3,753 Oct-21-2018, 07:08 PM
Last Post: oldcity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020