title: locating a password that corresponds to a username within an sqlite table
body: <p>I am running a website using Flask microframework and sqlite3 to store user logins. Currently, I am having trouble with matching the username and password entered by the user from an HTML form, with the existing records within my database. </p>
  
  <p>I am using the flask-login extension to help me with this, and when I try and match, I am receiving a TypeError: </p>
  
  <blockquote>
    <p>list indices must be integers or slices, not str</p>
  </blockquote>
  
  <p>here is my python code that is turning the SQLite table into a variable:</p>
  
  <pre><code>con = sql.connect("table.db")
  cur = con.cursor()
  cur.execute('SELECT * FROM users')
  names = cur.fetchall()
  </code></pre>
  
  <p>I then have this code which is taking the password from the HTML form, and trying to match it with the password linked to the username in the table</p>
  
  <pre><code>user_name = request.form['username']
  if request.form['password'] == names[user_name]['password']:
          user = User()
          user.id = user_name
          flask_login.login_user(user)
  </code></pre>
  
  <p>this is what 'names' returns:</p>
  
  <pre class="lang-json prettyprint-override"><code>[(7, 'ValidName', 'ValidTest', 'User@test.com'), (8, 'User2', 'password2', 'User@test2.com')]
  </code></pre>
  
  <p>What needs to happen is the program will check the form input for 'password' and will match it with the 'password' that is related to the username. So as an example, if <code>ValidName</code> and <code>ValidTest</code> were entered into the form, they would be requested by the program, and matched with the records found in 'names'.</p>