Jump to content

menator01

New Members
  • Posts

    7
  • Joined

  • Last visited

Posts posted by menator01

  1. My understanding of mvc

    model: handles all data such as get, add, and edit data. (From database or other form of data collection

    view: pretty much presentation. shows data retrieved

    controller: communicates between model and view.

    Model has no knowledge of view and vise versa

    controller is the go-between so to speak. controller has knowledge of both model and view.

    sometimes controller may contain some presentaion

  2. I realize this is an old topic but, wanted to reply.

    This is in no way a complete working script but, could do something like this.

    I would suggest using a database such as sqlite3 or mysql for storing user data or maybe a json file as it would make it easier.

     

    from string import ascii_letters, digits
    from random import sample
    
    characters = ascii_letters + digits + '@!?&#'
    
    def generate():
        return ''.join(sample(characters, 10))
    
    def check_newuser(new_user):
        if new_user:
            return True 
        return False
    
    def check(username, password):
        # Do user validation stuff
        if username:
            return True 
        return False
    
    main_menu = ['A: Login','B: Create Account','C: Quit']
    print('What would you like to do?')
    
    while True:
        print(f"Options: {', '.join(main_menu)}")
        option = input('Choose an option\n>> ')
    
        if option.lower() not in ['a','b','c']:
            print('That is not a valid option.')
    
        if option.lower() == 'c':
            print('Goodbye!')
            break
    
        if option.lower() == 'a':
            username = input('Please enter your username\n>> ')
            password = input('Please enter your password\n>> ')
            validate = check(username, password)
            if validate:
                print(f'User {username} logged in')
            else:
                print('Sorry that username or password is not correct.')
    
        if option.lower() == 'b':
            new_user = input('Please enter a username\n>> ')
            check_user = check_newuser(new_user)
            if check_user:
                print('Options: 1 create own password, 2 generate random password')
    
                new_password_option = input('Choose an option\n>> ')
                if new_password_option == '1':
                    newpass = input('Enter a new password\n>> ')
                elif new_password_option == '2':
                    newpass = generate()
                else:
                    print('That is not a valid option')
    
                print(f'Your password is {newpass}')
            else:
                print('That username has already been taken')
                # Go back and ask for new username

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.