2
import sys
import hashlib
import getpass
from passlib.hash import sha256_crypt
import MySQLdb, random, os


def SQLAddPass(username, password):
    SQL = 'insert into user values ("%s", "%s")' % (username, password)

    try:
        db = MySQLdb.connect (host='localhost', user='root', db='vedio')
        c = db.cursor()
        c.execute(SQL)
        db.commit()
        c.close()
        db.close()
        raw_input('Record Added - press enter to continue: ')
    except:
        print 'There was a problem adding the record'
        raw_input ('press enter to continue')


def main(argv):


    print '\nUser & Password Storage Program v.01\n'


    username = raw_input('Please Enter a User Name: ')
    password = sha256_crypt.encrypt(getpass.getpass('Please Enter a Password: '))

    try:
        SQLAddPass(username, password)

    except:
        sys.exit('There was a problem saving Record!')

    print '\nPassword safely stored in ' + sys.argv[1] + '\n'      

if __name__ == "__main__":
    main(sys.argv[1:])

My problem is that the script works but with the following error **

(C:\Users\Elsie\Desktop\example.py:14: Warning: Data truncated for column 'passwo rd' at row 1 c.execute(SQL) Record Added - press enter to continue:

**

Password safely stored in database. What am i doing wrong any ideas or changes to the code are welcome)

1
  • You have funny exception strategy. You are handling one exception two times. Don't. Commented Feb 20, 2013 at 9:10

2 Answers 2

1

Data truncated for column 'passwo rd' at row 1

Mean your table has a password column with a length of for example 10 and you are inserting a record of let's say 20. The record you inserted will be truncated. And passwords will be broken.

Increase length of column in the table

Sign up to request clarification or add additional context in comments.

Comments

0

Possible that your 'password' field is too short. You need a varchar(64). What is your length of your password field?

2 Comments

Julian i had used 15 but have increased as per suggestion and it works like a charm
@daniel thanks it worked can you please help with code to read and verify the stored password so far i have come up with this pass_try x = 3 username = raw_input('Please Enter User Name: ') while pass_try < x: password = sha256_crypt.verify(getpass.getpass("Enter password: ", hash)) if password != password: pass_try += 1print 'Incorrect Password, ' + str(x-pass_try) + ' more attemts left\n' else: pass_try = x+1 if pass_try == x and password != password: sys.exit('Incorrect Password, terminating... \n')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.