Preview:
def login():
    url = "http://localhost:3000/login"
    driver.get(url)
    driver.maximize_window()

    # get values from user to enter in the fields
    actual_name = "chaitra@br.com"
    actual_pwd = "123456"

    time.sleep(5)
    driver.find_element(By.XPATH, "//input[@name='email']").send_keys(actual_name)
    driver.find_element(By.XPATH, "//input[@name='password']").send_keys(actual_pwd)
    username = actual_name
    password = actual_pwd

    time.sleep(10)

    # Execute a query to retrieve the salted and hashed password for the specified user
    query = f"SELECT salted_hash_of_password FROM websocket_authentication_details WHERE email_id = %s and is_active " \
            f"= true "
    cursor.execute(query, (username,))
    result = cursor.fetchone()

    try:
        if result:
            stored_password_hash = result[0]
            user_input_password = password.encode('utf-8')

            # Verify the user's input password against the stored hash
            if bcrypt.checkpw(user_input_password, stored_password_hash.encode('utf-8')):
                query1 = f"SELECT permissions_json FROM websocket_permissions_details where email_id = %s"
                cursor.execute(query1, (username,))
                rows = cursor.fetchall()

                # Check for the keys present in Db for password verified user
                unique_keys = set()
                for row in rows:
                    json_data = row[0]
                    if json_data:
                        unique_keys.update(json_data.keys())
                unique_keys_list = list(unique_keys)

                # check if the user has the below keys in order to login
                values_to_check = ["data_permissions", "permit_actions"]
                for value in values_to_check:
                    if value in unique_keys_list:
                        try:
                            driver.find_element(By.XPATH, "//button[text()='Login']").click()
                            time.sleep(3)
                            val = key_check(username)
                            progress(val)
                            document_path = "D:/testfolder/test.dat"
                            order_blotter(document_path)
                        except NoSuchElementException:
                            print(" ")
            else:
                print("wrong pass")
                driver.find_element(By.XPATH, "//button[text()='Login']").click()
                time.sleep(5)
        else:
            print("user details not found")
            driver.find_element(By.XPATH, "//button[text()='Login']").click()
            time.sleep(3)
    except Exception as e:
        print("An unexpected error occurred:", e)

    cursor.close()
    conn.close()

    try:
        if "Wrong email or password." in driver.page_source:
            print("Wrong pass or username. Retry with correct login creds")
            driver.refresh()
        else:
            print("Login successful")
    except Exception as e:
        print("An unexpected error occurred:", e)
    time.sleep(10)
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter