Beispiel #1
0
def gethistory(id=None):
    if request.method == 'GET':
        history_sender = db.sqlSelect(
            "SELECT * FROM history where send_user = %s", (id))
        history_receive = db.sqlSelect(
            "SELECT * FROM history where receive_user = %s", (id))
        try:
            auth_history = {
                'message': 'pass',
                'data': {
                    'send': history_sender,
                    'receive': history_receive
                }
            }
            return auth_history
        except ValueError as Error:
            print(Error)
            auth_history = {
                'message': 'Error',
                'data': {
                    'send': [],
                    'receive': []
                }
            }
            return auth_history

    else:
        pass
Beispiel #2
0
def sendmoney():
    if request.method == 'POST':
        data = request.get_json()
        send_user = data['sendUser']
        receive_user = data['receiveUser']
        send_money = data['money']
        receive_bank = data['receiveUserBank']  #receive bak

        send_user_object = db.sqlSelect(
            "SELECT * FROM users where user_id = %s",
            (send_user))[0]  #get send bank
        try:
            #insert to history
            db.sql(
                "INSERT INTO history (send_user, receive_user, money, receive_bank,send_bank) VALUES (%s, %s, %s, %s, %s)",
                (send_user, receive_user, send_money, receive_bank,
                 send_user_object[9]))
            user = db.sqlSelect("SELECT * FROM users where user_id = %s",
                                (receive_user))

            #updata money for receiver
            money = float(user[0][8]) + float(send_money)
            db.sql("UPDATE users SET money = %s WHERE user_id = %s",
                   (money, receive_user))

            #updata money for sender
            money = float(send_user_object[8]) - float(send_money)
            db.sql("UPDATE users SET money = %s WHERE user_id = %s",
                   (money, send_user))
            return "pass"
        except ValueError as error:
            return "fail"
    else:
        pass
Beispiel #3
0
def auth():
    global username
    global user_directory
    global filename

    user_exist = False

    if request.method == 'POST':

        # Clien부터 보낸 username과 password를 받아
        data = request.get_json()

        # Model 저장하는 경로
        # user_directory = 'Models/wav/'
        username = data['username']
        user = db.sqlSelect(
            "SELECT * FROM users where user_id = %s and isvoice = 1",
            (username))

        if (len(user) == 0):
            print("[ * ] The user profile does not exists ...")
            return "Doesn't exist"
        else:
            print(type(user[0]))
            user_directory = 'Users/' + user[0][5] + '/'
            print("[ DEBUG ] : What is the user directory at auth : ",
                  user_directory)
            print("[ * ] The user profile exists ...")
            return "User exist"

    else:
        print('its coming here')
Beispiel #4
0
def getmony(id=None):
    if request.method == 'GET':
        user_money = db.sqlSelect("SELECT money FROM users where id = %s",
                                  (id))[0]
        auth_money = {'message': 'pass', 'data': user_money[0]}
        return auth_money
    else:
        pass
Beispiel #5
0
def loginwithnovoice():

    if request.method == 'POST':

        # Clien부터 보낸 username과 password를 받아
        data = request.get_json()

        # Model 저장하는 경로
        # user_directory = 'Models/wav/'
        username = data['username']
        password = data['password']
        cipher = AES.new(
            os.getenv("PASSWORD_ECD").encode('utf-8'),
            AES.MODE_ECB)  # never use ECB in strong systems obviously
        encoded_password = base64.b64encode(
            cipher.encrypt(password.encode('utf-8').rjust(32)))

        user = db.sqlSelect("SELECT * FROM users where user_id = %s",
                            (username))
        print(user)
        # 입력한 사용자를 존재하지 않음
        if (len(user) == 0):
            auth_message = {"message": "fail"}
        else:
            # 비밀번호 체크함
            password = user[0][2]
            print(encoded_password)
            if (password == encoded_password.decode('utf-8')):
                user = user[0]
                auth_message = {
                    "user": {
                        "id": user[0],
                        "user_id": user[1],
                        "email": user[3],
                        "isvoice": user[7],
                        "money": user[8]
                    },
                    "message": "pass"
                }
            else:
                auth_message = {"message": "fail"}
        return auth_message
    else:
        print('its coming here')
Beispiel #6
0
def checkuser():
    if request.method == 'POST':
        data = request.get_json()
        user = db.sqlSelect("SELECT * FROM users where user_id = %s",
                            (data['receiveUser']))
        if (len(user) == 0):
            auth_state = {
                'message': 'not exists',
            }
        else:
            bank = user[0][9]
            print(data['bankName'])
            if (bank == data['bankName']):
                auth_state = {
                    'message': 'exists',
                }
            else:
                auth_state = {
                    'message': 'not exists',
                }
        return auth_state
    else:
        pass
Beispiel #7
0
def enroll_no_voice():
    if request.method == 'POST':
        data = request.get_json()

        username = data['username']
        email = data['email']
        password = data['password']
        bankName = data['bankName']

        user = db.sqlSelect("SELECT * FROM users where user_id = %s",
                            (username))
        if (len(user) == 0):
            password = encoded_password(password)
            db.sql(
                "INSERT INTO users (user_id, password, email, bank) VALUES (%s, %s, %s, %s)",
                (username, password, email, bankName))
            print("new user join request pass")
            return "pass"
        else:
            print("user already exists")
            return "fail"
    else:
        return "no method for request"
Beispiel #8
0
def verify():
    global username
    global filename
    global user_directory
    global filename_wav

    print("[ DEBUG ] : user directory : ", user_directory)
    print("[ DEBUG ] : filename_wav : ", filename_wav)
    decrypt(getKey(os.getenv("PASSWORD_ECD")),
            user_directory + "encode" + username + ".wav")

    filename_wav = user_directory + "decode" + username + ".wav"
    print("[ DEBUG ] : filename_wav : ", filename_wav)
    # ------------------------------------------------------------------------------------------------------------------------------------#
    #                                                                LTSD and MFCC                                                     #
    # ------------------------------------------------------------------------------------------------------------------------------------#

    # (rate, signal) = scipy.io.wavfile.read(audio.get_wav_data())
    (rate, signal) = scipy.io.wavfile.read(filename_wav)

    extracted_features = extract_features(rate, signal)
    # ------------------------------------------------------------------------------------------------------------------------------------#
    #                                                          Loading the Gaussian Models                                                #
    # ------------------------------------------------------------------------------------------------------------------------------------#

    cipher = AES.new(os.getenv("GMM_ECD").encode('utf-8'),
                     AES.MODE_ECB)  # never use ECB in strong systems obviously
    encoded_path = base64.b64encode(
        cipher.encrypt(username.encode('utf-8').rjust(32))).decode('utf-8')
    user_gmm_path = removeSpecialChars(encoded_path)

    gmm_models = [
        os.path.join('Models/', user) for user in os.listdir('Models/')
        if user.endswith('.gmm')
    ]

    # decrypt(getKey(os.getenv("PASSWORD_ECD")), gmm_models)
    # gmm 리스트 파일 노드
    print("Load with GMM file: " + str(gmm_models))

    print("GMM Models : " + str(gmm_models))

    # Load the Gaussian user Models
    models = [pickle.load(open(user, 'rb')) for user in gmm_models]

    user_list = [user.split("/")[-1].split(".gmm")[0] for user in gmm_models]
    print("User List" + str(user_list))

    log_likelihood = numpy.zeros(len(models))

    for i in range(len(models)):
        gmm = models[i]  # checking with each model one by one
        scores = numpy.array(gmm.score(extracted_features))
        log_likelihood[i] = scores.sum()

    print("Log liklihood : " + str(log_likelihood))

    identified_user = numpy.argmax(log_likelihood)

    print("[ * ] Identified User : "******" - " +
          user_list[identified_user])

    auth_message = ""

    # 파일 이름 암호화
    cipher = AES.new(os.getenv("GMM_ECD").encode('utf-8'),
                     AES.MODE_ECB)  # never use ECB in strong systems obviously
    encoded_path = base64.b64encode(
        cipher.encrypt(username.encode('utf-8').rjust(32))).decode('utf-8')
    user_gmm_path = removeSpecialChars(encoded_path)
    print(user_gmm_path)
    if user_list[identified_user] == user_gmm_path:
        print("[ * ] You have been authenticated!")
        user = db.sqlSelect("SELECT * FROM users where pathgmm = %s",
                            (user_gmm_path + ".gmm"))[0]
        auth_message = {
            "user": {
                "id": user[0],
                "user_id": user[1],
                "email": user[3],
                "isvoice": user[7],
                "money": user[8]
            },
            "message": "pass"
        }
    else:
        print("[ * ] Sorry you have not been authenticated")
        auth_message = "fail"

    return auth_message