ConDict

Check-in [56ca0e3349]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:right check valid password
Timelines: family | ancestors | descendants | both | testing
Files: files | file ages | folders
SHA1:56ca0e33493eba4ecedc2230257af0d06942c12a
User & Date: zorro 2012-09-01 17:48:09
Context
2012-09-01
19:20
done add new users check-in: c6a5356e98 user: zorro tags: testing
17:48
right check valid password check-in: 56ca0e3349 user: zorro tags: testing
13:23
check user (sql select) check-in: 4f9e9a59f3 user: zorro tags: testing
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to condt.conf.

1
2
3
4
5
[database]
dbname=db.sqlite

[user]
default_user=u1




|
1
2
3
4
5
[database]
dbname=db.sqlite

[user]
#default_user=u1

Changes to condt.py.

1
2
3
4

5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23




24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48














49
50
51








52
53
54

55
56
57
58
59
60




#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import sqlite3, hashlib


class Condt():
    """Condt - base class for ConDict"""


    def __init__(self, name, password, dbfile):

        self.name = name
        self.password = password
        self.connect = sqlite3.connect(dbfile)
        self.user_id = None
        if self.get_user() != 0:
            self.handling_action()
        print(self.user_id)

    def __repr__(self):
        return "<ConDict object for {0}>".format(self.name)

    def __str__(self):
        return "<ConDict object for {0}>".format(self.name)





    def __del__(self):
        self.connect.close()

    def get_user(self):
        sqlstr="SELECT id FROM user WHERE name=(?) AND password=(?)"
        cur = self.connect.cursor()
        try:
            cur.execute(sqlstr, (self.name, self.hash_pass(self.password)))
            result = cur.fetchone()
            if result:
                self.user_id = result[0]
            else:
                return 1
        except (sqlite3.DatabaseError, TypeError)  as er:
            print('error')
        cur.close()
        return 0

    def hash_pass(self, password):
        return password
    def hash_pass1(self, password):
        result = bytes(password.strip().lower(), 'utf-8')
        return hashlib.sha1(result).hexdigest()















    def handling_action(self):
        while(True):
            action = input('Sorry, not found user, there are actions "Add new user"/"Press password again" [a/P]:')








            if action in ('', 'P', 'p'):
                print('press')
                break

            elif action in ('a', 'A'):
                print('add', self.name)
                break
            else:
                print('select an option...')
        print('ok')







|
>





|
>

<

|
<
<
<






>
>
>
>







|
|
|
|
|
|
<
<
|

|







>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
<
>
>
>
>
>
>
>
>
|
<
<
>
|
<
|
|
|
<
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63


64
65
66
67
68
69
70
71
72


73
74

75
76
77

78
79
80
81
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import sqlite3, hashlib, getpass
DEBUG = True

class Condt():
    """Condt - base class for ConDict"""


    def __init__(self, name, dbfile):
        self.__pcounter = 3
        self.name = name

        self.connect = sqlite3.connect(dbfile)
        self.user_id = self.get_user()




    def __repr__(self):
        return "<ConDict object for {0}>".format(self.name)

    def __str__(self):
        return "<ConDict object for {0}>".format(self.name)

    def __bool__(self):
        valid = True if self.user_id else False
        return valid

    def __del__(self):
        self.connect.close()

    def get_user(self):
        sqlstr="SELECT id FROM user WHERE name=(?) AND password=(?)"
        cur = self.connect.cursor()
        ch_user_id = self.check_name(cur)
        if ch_user_id:
            ch_user_id = ch_user_id[0]
            # check pass
            return self.handling_action(cur, ch_user_id)
        else:


            print('add')
        cur.close()
        return None

    def hash_pass(self, password):
        return password
    def hash_pass1(self, password):
        result = bytes(password.strip().lower(), 'utf-8')
        return hashlib.sha1(result).hexdigest()

    def check_name(self, cur):
        try:
            cur.execute("SELECT id FROM user WHERE name=(?)", (self.name,))
        except sqlite3.DatabaseError as er:
            return None
        return cur.fetchone()

    def check_password(self, cur, user_id):
        try:
            cur.execute("SELECT id FROM user WHERE id=(?) AND password=(?)", (user_id, self.password))
        except sqlite3.DatabaseError as er:
            return None
        return cur.fetchone()

    def handling_action(self, cur, ch_user_id):


        print('"{0}" please enter your password:'.format(self.name))
        while(self.__pcounter > 0):
            self.password = input("Password:") if DEBUG else getpass.getpass()
            user_id = self.check_password(cur, ch_user_id)
            if user_id:
                return user_id[0]
            else:
                action = input('Invalid password, there are actions "Exit"/"Press password again" [e/P]:')
                if action in ('', 'P', 'p'):


                    self.__pcounter -= 1
                elif action in ('e', 'E'):

                    break
                else:
                    print('select an option...')

        return None

    def handling_add(self, cur):
        pass

Added db.sql.



















>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
CREATE TABLE "progress" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "translate_id" INTEGER NOT NULL , "all" INTEGER DEFAULT 0, "error" INTEGER DEFAULT 0);
CREATE TABLE "term" ("token" VARCHAR(40) PRIMARY KEY  NOT NULL  UNIQUE , "en" VARCHAR NOT NULL );
CREATE TABLE "translate" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "term" VARCHAR(40) NOT NULL , "user_id" INTEGER NOT NULL , "rus" VARCHAR NOT NULL );
CREATE TABLE "user" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , "name" VARCHAR NOT NULL  UNIQUE , "password" VARCHAR NOT NULL , "full" TEXT);
CREATE INDEX "progress_result" ON "progress" ("all" ASC, "error" ASC);
CREATE INDEX "progress_translate" ON "progress" ("translate_id" ASC);
CREATE INDEX "translate_user_id" ON "translate" ("user_id" ASC);
CREATE UNIQUE INDEX "user_name" ON "user" ("name" ASC);
CREATE INDEX "user_passwod" ON "user" ("password" ASC);

Changes to db.sqlite.

cannot compute difference between binary files

Changes to main.py.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#-*- coding: utf-8 -*-

from aside import *
from condt import Condt
import getpass, os

CONF_NAME = 'condt.conf' 
DEBUG = True

def main():
    global CONF_NAME
    # user-name query
    config = get_config_data(CONF_NAME)
    print(config['database'])
    if not os.path.exists(config['database']):
        print("Not fount SQLite database")
        return 1
    # get name
    user = config['defuser'] if config['defuser'] else input("User name:")
    # get password
    print('"{0}" please enter your password:'.format(user))
    password = input("Password: ") if DEBUG else getpass.getpass()

    # create object
    account = Condt(user, password, config['database'])
    print(account)




if __name__ == "__main__":
    main()







|











|
|
|
|
|
<







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
#-*- coding: utf-8 -*-

from aside import *
from condt import Condt
import getpass, os

CONF_NAME = 'condt.conf' 


def main():
    global CONF_NAME
    # user-name query
    config = get_config_data(CONF_NAME)
    print(config['database'])
    if not os.path.exists(config['database']):
        print("Not fount SQLite database")
        return 1
    # get name
    user = config['defuser'] if config['defuser'] else input("User name:")
    # create object
    account = Condt(user, config['database'])
    if not account:
        print('Validation error, bye...')
        return 0

    print(account)




if __name__ == "__main__":
    main()