Quiz

  1. In the code, why does the application display the user's UID after registration if the UID is mainly used internally by the database. Is there any reason the user would need to know it?

    This is an excellent point. You are probably right that the user does not need to know their UID.

    For example, my health provider app has a "medical record number" for me — an ID. I know because it's displayed. I've never needed it because when I call and give my name and birthdate, that turns out to be unique. But if it weren't, the MRN would do the trick.

    So, I can imagine scenarios where that UID would be useful, but they aren't common.

    On the other hand, there's no harm to showing their UID.

    And, in this case, I found it pedagogically useful.

  2. in your example below, how much do you recommend telling a user that the username is taken, because wouldn't this allow attackers to create a list of valid usernames/figure out who has accounts, and try to hack them knowing that they exist?
    
                try:
                    curs.execute('''INSERT INTO userpass(uid,username,password_hash)
                                    VALUES(null,%s,%s)''',
                                    [username, hashed])
                    conn.commit()
                except pymysql.IntegrityError as err:
                    flash(f'Username taken: {err}')
                    return redirect(url_for('index'))
    
    

    This is a good point. We want to give attackers as little information as we can.

    However, I think in this case we run into a conflict between usability and security. I think we have to tell the user what has gone wrong, so that they can fix the problem.

    The main line of defense is strong passwords (minimum length/entropy). Not revealing whether a username is correct is helpful but not the main thing.

    Consider that anyone who has ever seen my email address knows to attack sanderso.

  3. Throwback to last lesson but what actually is the difference between cookies and cache?

    They are two very different ideas.

    • A cache is a general-purpose mechanism to avoid re-doing work that has already been done, in particular retrieving again something that you previously retrieved.

      In processors, a cache avoids getting something from memory if you already got it recently.

      In browsers, a cache avoids getting a file (CSS file, Logo image, JS file, etc) from the server that has previously been retrieved.

      When I was a kid, I learned the word "cache" in a story about a hunter who had a cache of supplies hidden in the woods, so he didn't have to go back home for them.
    • A cookie is a token that is included as part of the headers of a browser request and a server response, so it goes back and forth between browser and server. It can carry information that provides continuity across a series of interactions.
  4. Why do we need both salt and a slow hashing algorithm to protect passwords?

    The slow hashing is critical, because of brute-force attacks.

    The salt makes that a bit harder because (1) the attacker can't pre-compute hashes of common passwords, and (2) a reused password will still have a different hash.

  5. This was an interesting reading!

    I'm so glad! Thanks for telling me.