MCPcopy Index your code
hub / github.com/InstaPy/InstaPy / two_factor_authentication

Function two_factor_authentication

instapy/login_util.py:616–691  ·  view source on GitHub ↗

Check if account is protected with Two Factor Authentication codes Args: :browser: Web driver :logger: Library to log actions :security_codes: List of Two Factor Authentication codes, also named as Recovery Codes. Returns: None

(browser, logger, security_codes)

Source from the content-addressed store, hash-verified

614
615
616def two_factor_authentication(browser, logger, security_codes):
617 """
618 Check if account is protected with Two Factor Authentication codes
619
620 Args:
621 :browser: Web driver
622 :logger: Library to log actions
623 :security_codes: List of Two Factor Authentication codes, also named as Recovery Codes.
624
625 Returns: None
626 """
627
628 # Wait until page is loaded after user and password were introduced
629 sleep(random.randint(3, 5))
630
631 if "two_factor" in browser.current_url:
632
633 logger.info("- Two Factor Authentication is enabled...")
634
635 # Chose one code from the security_codes list
636 # 0000 is used if no codes were provided in constructor.
637 code = random.choice(security_codes)
638
639 try:
640 # Check Security code is numeric
641 int(code)
642
643 verification_code = read_xpath(login_user.__name__, "verification_code")
644 explicit_wait(browser, "VOEL", [verification_code, "XPath"], logger)
645
646 security_code = browser.find_element(By.XPATH, verification_code)
647
648 # Confirm blue button
649 confirm = browser.find_element(
650 By.XPATH, read_xpath(login_user.__name__, "confirm")
651 )
652
653 (
654 ActionChains(browser)
655 .move_to_element(security_code)
656 .click()
657 .send_keys(code)
658 .perform()
659 )
660
661 sleep(random.randint(1, 3))
662
663 (
664 ActionChains(browser)
665 .move_to_element(confirm)
666 .click()
667 .send_keys(Keys.ENTER)
668 .perform()
669 )
670
671 # update server calls for both 'click' and 'send_keys' actions
672 for _ in range(2):
673 update_activity(browser, state=None)

Callers 1

login_userFunction · 0.85

Calls 4

sleepFunction · 0.85
read_xpathFunction · 0.85
explicit_waitFunction · 0.85
update_activityFunction · 0.85

Tested by

no test coverage detected