# # These functions need to be implemented
# user =	"secret"
# password =	"noPow3r"
# endpoint =	"bootcamp-tht.sre.wize.mx"
# DB =	"bootcamp_tht"

import json
from logging import RootLogger
import jwt
from jwt import algorithms
import hashlib
import mysql.connector
from flask import Flask, render_template
from cryptography.hazmat.primitives import serialization
# read and load the key

def validation():
  mydb = mysql.connector.connect(
    host="bootcamp-tht.sre.wize.mx",
    user="secret",
    password="noPow3r",
    database="bootcamp_tht"
  )
  mycursor = mydb.cursor()
  mycursor.execute("SELECT * FROM users")
  myresult = mycursor.fetchall()
  print(type(myresult))

  for row in myresult:
    if row[0] == "admin":
      role = row[3]    
      salt = row [2]
      passw = row[1]
      usern = row [0]
      print("this is role",role)
      print("this is salt",salt)
      print("this is pass",passw)
      print("this is userame",usern)
      break
    else:
      continue
  #to get 512 hash from passw give from user

  salty = str(salt)
  usr_pass = "secret"
  string = (usr_pass+salty)
  salt_f = hashlib.sha512(string.encode()).hexdigest()
  print(len(salt_f))
  print(len(salt))

  if salt_f == passw:
    print("yes")
    payload = {"role": role}
  return payload

test = validation()
payload_data = test

secret = "my2w7wjd7yXF64FIADfJxNs1oupTGAuW"


class Token:
    def generate_token(self, username, password):        
        token_jwt = jwt.encode(payload_data,secret,algorithm="HS256").decode('utf-8')
        return token_jwt


class Restricted:

    def access_data(self, authorization):
        return 'You are under protected data.'


ee2b222fd706debffd9a565354e455ee5a45c285
<mask token>


class Token:

    def generate_token(self, username, password):
        token_jwt = jwt.encode(payload_data, secret, algorithm='HS256').decode(
            'utf-8')
        return token_jwt


class Restricted:

    def access_data(self, authorization):
        return 'You are under protected data.'

<mask token>


def validation():
    mydb = mysql.connector.connect(host='bootcamp-tht.sre.wize.mx', user=
        'secret', password='noPow3r', database='bootcamp_tht')
    mycursor = mydb.cursor()
    mycursor.execute('SELECT * FROM users')
    myresult = mycursor.fetchall()
    print(type(myresult))
    for row in myresult:
        if row[0] == 'admin':
            role = row[3]
            salt = row[2]
            passw = row[1]
            usern = row[0]
            print('this is role', role)
            print('this is salt', salt)
            print('this is pass', passw)
            print('this is userame', usern)
            break
        else:
            continue
    salty = str(salt)
    usr_pass = 'secret'
    string = usr_pass + salty
    salt_f = hashlib.sha512(string.encode()).hexdigest()
    print(len(salt_f))
    print(len(salt))
    if salt_f == passw:
        print('yes')
        payload = {'role': role}
    return payload


<mask token>


class Token:

    def generate_token(self, username, password):
        token_jwt = jwt.encode(payload_data, secret, algorithm='HS256').decode(
            'utf-8')
        return token_jwt


class Restricted:

    def access_data(self, authorization):
        return 'You are under protected data.'

<mask token>


def validation():
    mydb = mysql.connector.connect(host='bootcamp-tht.sre.wize.mx', user=
        'secret', password='noPow3r', database='bootcamp_tht')
    mycursor = mydb.cursor()
    mycursor.execute('SELECT * FROM users')
    myresult = mycursor.fetchall()
    print(type(myresult))
    for row in myresult:
        if row[0] == 'admin':
            role = row[3]
            salt = row[2]
            passw = row[1]
            usern = row[0]
            print('this is role', role)
            print('this is salt', salt)
            print('this is pass', passw)
            print('this is userame', usern)
            break
        else:
            continue
    salty = str(salt)
    usr_pass = 'secret'
    string = usr_pass + salty
    salt_f = hashlib.sha512(string.encode()).hexdigest()
    print(len(salt_f))
    print(len(salt))
    if salt_f == passw:
        print('yes')
        payload = {'role': role}
    return payload


test = validation()
payload_data = test
secret = 'my2w7wjd7yXF64FIADfJxNs1oupTGAuW'


class Token:

    def generate_token(self, username, password):
        token_jwt = jwt.encode(payload_data, secret, algorithm='HS256').decode(
            'utf-8')
        return token_jwt


class Restricted:

    def access_data(self, authorization):
        return 'You are under protected data.'

import json
from logging import RootLogger
import jwt
from jwt import algorithms
import hashlib
import mysql.connector
from flask import Flask, render_template
from cryptography.hazmat.primitives import serialization


def validation():
    mydb = mysql.connector.connect(host='bootcamp-tht.sre.wize.mx', user=
        'secret', password='noPow3r', database='bootcamp_tht')
    mycursor = mydb.cursor()
    mycursor.execute('SELECT * FROM users')
    myresult = mycursor.fetchall()
    print(type(myresult))
    for row in myresult:
        if row[0] == 'admin':
            role = row[3]
            salt = row[2]
            passw = row[1]
            usern = row[0]
            print('this is role', role)
            print('this is salt', salt)
            print('this is pass', passw)
            print('this is userame', usern)
            break
        else:
            continue
    salty = str(salt)
    usr_pass = 'secret'
    string = usr_pass + salty
    salt_f = hashlib.sha512(string.encode()).hexdigest()
    print(len(salt_f))
    print(len(salt))
    if salt_f == passw:
        print('yes')
        payload = {'role': role}
    return payload


test = validation()
payload_data = test
secret = 'my2w7wjd7yXF64FIADfJxNs1oupTGAuW'


class Token:

    def generate_token(self, username, password):
        token_jwt = jwt.encode(payload_data, secret, algorithm='HS256').decode(
            'utf-8')
        return token_jwt


class Restricted:

    def access_data(self, authorization):
        return 'You are under protected data.'

# # These functions need to be implemented
# user =	"secret"
# password =	"noPow3r"
# endpoint =	"bootcamp-tht.sre.wize.mx"
# DB =	"bootcamp_tht"

import json
from logging import RootLogger
import jwt
from jwt import algorithms
import hashlib
import mysql.connector
from flask import Flask, render_template
from cryptography.hazmat.primitives import serialization
# read and load the key

def validation():
  mydb = mysql.connector.connect(
    host="bootcamp-tht.sre.wize.mx",
    user="secret",
    password="noPow3r",
    database="bootcamp_tht"
  )
  mycursor = mydb.cursor()
  mycursor.execute("SELECT * FROM users")
  myresult = mycursor.fetchall()
  print(type(myresult))

  for row in myresult:
    if row[0] == "admin":
      role = row[3]    
      salt = row [2]
      passw = row[1]
      usern = row [0]
      print("this is role",role)
      print("this is salt",salt)
      print("this is pass",passw)
      print("this is userame",usern)
      break
    else:
      continue
  #to get 512 hash from passw give from user

  salty = str(salt)
  usr_pass = "secret"
  string = (usr_pass+salty)
  salt_f = hashlib.sha512(string.encode()).hexdigest()
  print(len(salt_f))
  print(len(salt))

  if salt_f == passw:
    print("yes")
    payload = {"role": role}
  return payload

test = validation()
payload_data = test

secret = "my2w7wjd7yXF64FIADfJxNs1oupTGAuW"


class Token:
    def generate_token(self, username, password):        
        token_jwt = jwt.encode(payload_data,secret,algorithm="HS256").decode('utf-8')
        return token_jwt


class Restricted:

    def access_data(self, authorization):
        return 'You are under protected data.'

