Exemplo n.º 1
0
def adduser():
    try:
        user = request.form['UID']
        password = request.form['pass']
        conpass = request.form['conpass']
        Tower = request.form['tower'].lower()
        context = request.form['context'].lower()
        user_en = encryption.encrypt_password("AutoFact", user)
        pass_en = encryption.encrypt_password("AutoFact", password)

        #to_csv(user_en,pass_en,Tower,context)
        if (password == conpass):
            write_CSV = open('./text.csv', 'a')
            check = exists(user_en, Tower)
            if (check == "notexists"):
                write_CSV.write(
                    str(user_en) + "::!::" + str(pass_en) + "::!::" +
                    str(Tower) + "::!::" + str(context) + "\n")
                write_CSV.close()
                return 'Hello   User {} is created for {} Sucessfully...!!!'.format(
                    user, Tower)
            else:
                write_CSV.close()
                return 'Hello   User {} for {} already exists...!!!'.format(
                    user, Tower)
        else:
            return 'Please enter same value for password and confirm password...!!!'
        return listuser()
    except Exception as e:
        LogGenModule.exception(e)
Exemplo n.º 2
0
def upuser():
    try:
        user = request.form['UID']
        expass = request.form['oldspass']
        password = request.form['pass']
        conpass = request.form['conpass']
        Tower = request.form['tower'].lower()
        context = request.form['context'].lower()
        user_en = encryption.encrypt_password("AutoFact", user)
        pass_en = encryption.encrypt_password("AutoFact", expass)
        verification = verify_pass(user_en, Tower, pass_en)
        if (verification == "success"):
            if (len(conpass) > 0):
                if (password == conpass):
                    newpass_en = encryption.encrypt_password(
                        "AutoFact", conpass)
                    res = mod_csv(user_en, newpass_en, Tower, context)
                else:
                    return "Please enter same vale for password and confirm password"
            else:
                res = mod_csv(user_en, pass_en, Tower, context)
        else:
            return "correct value for old password"
        #return render_template('listuser')
        return listuser()
    except Exception as e:
        LogGenModule.exception(e)
Exemplo n.º 3
0
def add_password(name, password, user_password):

    data_dict = {}
    IV = get_iv()
    password = encrypt_password(
        user_password, password, IV
    )  #Encoding the password, so someone with access to the computer won't be able to get it!
    password = password.decode()
    IV = base64.urlsafe_b64encode(IV)
    IV = IV.decode()

    try:
        with open(
                'data.json', 'r'
        ) as f:  #First reading the data file and getting the Dictonary inside
            data_dict = json.load(f)
            f.close()
            data_dict[name] = [password, IV]

    except:
        error_message("No data file", "Creating data file now...",
                      "Data Error")

    with open(
            'data.json', 'w'
    ) as f:  #Then writing the new Dictonary with the new Name and Password
        json.dump(data_dict, f)
        f.close()
Exemplo n.º 4
0
def update_password(name, new_password, user_password):

    data_dict = {}
    IV = get_iv()
    password = encrypt_password(
        user_password, new_password,
        IV)  #Make sure the new password is incoded with the Key Password
    password = password.decode()
    IV = base64.urlsafe_b64encode(IV)
    IV = IV.decode()

    try:
        with open(
                'data.json', 'r'
        ) as f:  #Again read the Dictonary from the JSON file and then write the updated one!
            data_dict = json.load(f)
            f.close()
            data_dict[name] = [password, IV]
    except:
        error_message("No data file", "Creating data file now...",
                      "Data Error")

    with open('data.json', 'w') as f:
        json.dump(data_dict, f)
        f.close()
Exemplo n.º 5
0
    def login(self):
        # 打开登录首页
        url = '{domain}/login_pc.htm'.format(domain=self.domain)
        self.session.get(url=url, headers=self.headers.copy())

        # 获取秘钥, 用于加密用户密码
        headers = self.headers.copy()
        headers['Referer'] = url
        resp = self.session.get(
            url=self.domain +
            'router/get_rand_key.cgi?noneed=noneed&_=1471006585938',
            headers=headers)
        random_key = resp.json()["rand_key"]

        # 根据获取到的秘钥加密password
        encrypted_password = random_key[:32] + encrypt_password(
            random_key[:32], self.password)

        # 用加密后的密码登录并获取token
        resp = self.session.post(url=self.domain + '/router/web_login.cgi',
                                 data={
                                     'user': '******',
                                     'pass': encrypted_password,
                                     'from': 1
                                 },
                                 headers=headers)
        token_id = resp.json()['token_id']
        self.token_id = token_id

        return token_id
Exemplo n.º 6
0
def add_new_user(db, cursor, DB_NAME, val):
    # Menambahkan data pengguna baru
    # @Param
    # db : database yang sedang connect
    # cursor : cursor database
    # DB_Name : nama database
    # val : tupple nama_pengguna, username, password, email, alamat, tanggal_lahir, nomor_telepon
    # Note, password belum diencrypsi
    # Return pesan sukses/error beserta kodenya
    val[2] = encrypt_password(val[2])

    cursor.execute("USE {}".format(DB_NAME))
    try:
        sql_addUser = (
            "INSERT INTO user(nama_pengguna, username, password, email, alamat, tanggal_lahir, nomor_telepon)"
            "VALUES (%s, %s, %s, %s, %s, %s, %s);")
        cursor.execute(sql_addUser, val)

        log_id = cursor.lastrowid
        sql_addKlien = ("INSERT INTO klien(ID_Pengguna)" "VALUES (%s);")
        cursor.execute(sql_addKlien, [log_id])

        db.commit()

        print("Menambahkan User dengan id {}".format(log_id))
        return [1, "Menambahkan User dengan id" + str(log_id)]
    # Ada duplicate
    except mysql.connector.IntegrityError as err:
        # print(err.msg)
        return [-1, err.msg]
    # Error lainnya
    except mysql.connector.Error as err:
        # print(err.msg)
        return [0, err.msg]
Exemplo n.º 7
0
def delete_user():
    try:
        user = request.form['UID']
        expass = request.form['oldspass']
        Tower = request.form['tower'].lower()
        context = request.form['context'].lower()
        user_en = encryption.encrypt_password("AutoFact", user)
        pass_en = encryption.encrypt_password("AutoFact", expass)
        verification = verify_pass(user_en, Tower, pass_en)
        if (verification == "success"):
            res = del_csv(user_en, pass_en, Tower, context)
        else:
            return "provide correct value for password"
        #return render_template('listuser')
        return listuser()
    except Exception as e:
        LogGenModule.exception(e)
Exemplo n.º 8
0
def append_new(website, username, password):
    current = con.cursor()

    encrypted_password = encryption.encrypt_password(
        password, master_password).encode('utf-8').hex()
    current.execute(
        "insert into passwords(website, username, password) values (?, ?, ?) ",
        (website, username, encrypted_password))
    con.commit()
    con.close()
Exemplo n.º 9
0
def prepare_new_user_data(username, password):
    """
    Return user data ready for storage.
    :return: A Dict containing user data ready to store, including encrypted password.
    """
    new_user = {
        'username': username,
        'password': encrypt_password(password),
        'created': str(datetime.datetime.now()),
        'active': True
    }
    return new_user
Exemplo n.º 10
0
def deleteuser():
    try:
        user = request.args.get('UID')
        Tow = request.args.get('tower')
        Tower = Tow.lower()
        cont = request.args.get('context')
        context = cont.lower()
        user_en = encryption.encrypt_password("AutoFact", user)
        result = []
        result.append(user + "!" + Tower + "!" + context)
        results = result
        return render_template('del_user.html', results=results)
    except Exception as e:
        LogGenModule.exception(e)
Exemplo n.º 11
0
import random
import pytest
import mysql.connector
from encryption import encrypt_password, check_password
from autentikasi import *

# Test Enkripsi
password = ["", "a", "4200", "-21"]
encrypt = []
for pw in password:
    encrypt.append(encrypt_password(pw))

pe = []
for i in range(len(password)):
    pe.append((password[i], encrypt[i]))


@pytest.mark.parametrize("password, encrypt", pe)
def test_check_encrypt(password, encrypt):
    """Test Apakah Enkripsi Berhasil
    """
    assert check_password(password, encrypt) == True


# Test Database SQL
config = {"user": "******", "password": "******", "host": "localhost"}

DB_NAME = "Cover_Me"
db = mysql.connector.connect(**config)

# Cursor database
    

def mod_csv(user):
    
    rnum = user
    file1 = open('qwe.csv', 'r')
    file2 = open('file11.csv', 'a')
    for line in file1:
        print(line)
        row = line.split("::!::")
        if row[0] == rnum:
            row[2] = "sravani"
            continue
        else :
            file2.write(str(row[0])+"::!::"+str(row[1])+"::!::"+str(row[2]))
    file1.close()
    file2.close()
    shutil.move("./file11.csv","./qwe.csv")

if __name__=='__main__':
    
    user = input("enter username : "******"enter old password : "******"enter new password : "******"enter tower : ")
    context = input("enter the context : ")
    user_en = encryption.encrypt_password("AutoFact", user)
    pass_en = encryption.encrypt_password("AutoFact", password)
    to_csv(user_en,pass_en,Tower,context)
    #mod_csv(user)
Exemplo n.º 13
0
 def encrypt_password(self, password, salt):
     return encrypt_password(password, salt, self.bytes)