def claim(foundPosition): previousChecks() pyautogui.click(foundPosition) band = False retry = 0 while not band: checkbox = pyautogui.locateOnScreen( 'pycho2/notARobotCheck.png') or pyautogui.locateOnScreen( 'pycho2/notARobotBlue.png') or pyautogui.locateOnScreen( 'pycho2/notARobotRed.png') hideDetails = pyautogui.locateOnScreen('pycho2/hideDetails.png') if checkbox is not None: pyautogui.click(checkbox) pyautogui.moveTo(checkbox[0] - 100, checkbox[1] + 100) band = True elif hideDetails is not None: pyautogui.click(hideDetails) else: retry += 1 if retry == 3: band = True refresh.refreshMiner() return None captchaList = [ 'pycho2/tiki.png', 'pycho2/headphone.png', 'pycho2/eye.png', 'pycho2/notARobotRed.png' ] position = 0 retry = 0 approved = False detected = False while not approved and not detected and retry < 3: foundPosition = pyautogui.locateOnScreen(captchaList[position]) if foundPosition is not None: if position > 0 and position < 3: detected = captcha.captcha() position = 0 elif position == 0: pyautogui.click('pycho2/approve.png') pyautogui.move(0, -100) logger.info('Aprobado') approved = True if pyautogui.locateOnScreen('pycho2/approve.png') is not None: refresh.localizeClaimingTlmAndHitRefresh() elif position == 3: pyautogui.click('pycho2/notARobotRed.png') detected = captcha.captcha() elif position < len(captchaList) - 1: position += 1 else: position = 0 retry += 1 tout = time.time()
def login_form(self): if 'do' in request.args and request.args['do'] == 'captcha_img': if 'captcha' not in session: abort(503) else: response = make_response(session['captcha'].image()) response.headers.add('Content-Type', 'image/png') return response if 'force_update_sq' in session: return redirect('/pldt/auth?sq') if 'next' in request.args: next_page = request.args['next'] else: next_page = utils.extract_nextpage(request, self.wide) captcha_form = False if 'captcha_active' in session: captcha_form = True session['captcha'] = captcha(request.gateway_session_id) self.log.info('Captcha Validation: %s', session['captcha']._generate_words()) session['next'] = next_page request.response.data = render_template_string(request.templates['login'], templates=request.template_objects, organizations=self.wide.organizations, captcha_form=captcha_form) return request.response
def login_form(self): if 'do' in request.args and request.args['do'] == 'captcha_img': if 'captcha' not in session: abort(503) else: response = make_response(session['captcha'].image()) response.headers.add('Content-Type', 'image/png') return response if 'sq' in request.args: if not self.model.security_questions: self.model.security_questions = request.kenan.GetSecurityQuestions() print 'SEC Qs', self.model.security_questions request.response.data = render_template_string(request.templates['security_question_redirection'], security_questions=self.model.security_questions, templates=request.template_objects) return request.response if 'next' in request.args: next_page = request.args['next'] else: next_page = utils.extract_nextpage(request, self.wide) captcha_form = False if 'captcha_active' in session: captcha_form = True session['captcha'] = captcha(request.cookies['sessid']) self.log.info('Captcha Validation: %s', session['captcha']._generate_words()) session['next'] = next_page request.response.data = render_template_string(request.templates['login'], templates=request.template_objects, organizations=self.wide.organizations, captcha_form=captcha_form) return request.response
def lost_password_form(self): if 'do' in request.args and request.args['do'] == 'captcha_img': if 'pw_captcha' not in session: abort(503) else: response = make_response(session['pw_captcha'].image()) response.headers.add('Content-Type', 'image/png') return response phase = int(request.args['phase']) if 'phase' in request.args else 1 if phase == 1: session.wipe(exception_keys=['_flashes']) session['confirmation_form_type'] = 'lost_password' request.response.data = render_template_string(request.templates['lost_password1'], templates=request.template_objects) elif phase == 2 and 'confirmation_email_address' in session: session['security_qa'] = security_qa = request.kenan.GetUserSecurityQuestion(session['confirmation_email_address']) if security_qa == False: self.log.info('Lost password for %s kenan security question query failed', session['confirmation_email_address']) session.destroy() flash(self.model.spiel('system_timeout', code='17ba0'), 'error') return redirect(url_for('lost_password_form')) request.response.data = render_template_string(request.templates['lost_password2'], security_qa=security_qa, templates=request.template_objects) elif phase == 3 and 'confirmation_answer_ok' in session: if 'pw_captcha' not in session: session['pw_captcha'] = captcha(request.gateway_session_id) self.log.info('Captcha Validation: %s', session['pw_captcha']._generate_words()) request.response.data = render_template_string(request.templates['lost_password3'], templates=request.template_objects) else: return redirect('/lost_password?phase=1') return request.response
def scu_login(self, j_username, j_password): """ 这里登录教务处网站,使之前得到的session和自己的身份联系在一起,从而使得session的身份验证生效 """ captcha_class = captcha(self.s) j_captcha = captcha_class() print("********************************") print("开始模拟登陆四川大学本科教务系统") postUrl = 'http://zhjw.scu.edu.cn/j_spring_security_check' postData = { "j_username": j_username, "j_password": j_password, "j_captcha": j_captcha, } print("用户名为:", j_username) print("密码为:", j_password) print("验证码为:", j_captcha) try: r = self.s.post(postUrl, data=postData, headers=self.headers) r.raise_for_status() r.encoding = r.apparent_encoding if self.is_login(r.text): print("登录成功") else: print("用户名和密码错误") return self.is_login(r.text) # print(s.cookies.get_dict()) # print(r.text) except: print(r.text) print("登录失败", r.status_code) return False finally: print("********************************")
def login(username, password): logined, connected = checkState() if logined: return True, "已登录." elif not connected: return False, "未连接!" openPage("http://192.168.3.11:7001/QDHWSingle/loginlg.jsp") captchaUrl = ''.join(['http://192.168.3.11:7001/QDHWSingle/', 'ValidateCodeServlet?action=ShowValidateCode1']) validatecode = captcha.captcha(openPage(captchaUrl)) postData = { 'from': '1g', 'logName': str(username), 'logPW': str(password), 'validatecode': validatecode, } openPage('http://192.168.3.11:7001/QDHWSingle/login.do', postData) for i in range(20): logined, connected = checkState() if logined: return True, "登录成功." else: return False, "登录失败!"
def register_get(): image, captcha_str = captcha.captcha() img_name = 'static/images/{}.jpg'.format(time.time()) print(img_name) image.save(img_name, 'jpeg') print(captcha_str) return render_template('register.html', img_name=img_name, captcha_str=captcha_str)
def scu_login(self, username, password): """ 这里登录教务处网站,使之前得到的session和自己的身份联系在一起,从而使得session的身份验证生效 """ captcha_class = captcha(self.s) j_captcha = captcha_class() print("********************************") print("开始模拟登陆四川大学本科教务系统") postUrl = 'http://zhjw.scu.edu.cn/j_spring_security_check' # 加入MD5加密hash hl = hashlib.md5() hl.update(password.encode(encoding='utf-8')) j_password = hl.hexdigest() postData = { "j_username": username, "j_password": j_password, "j_captcha": j_captcha, } print("用户名为:", username) print("密码为:", password) print("密码MD5值:", j_password) print("验证码为:", j_captcha) try: r = self.s.post(postUrl, data=postData, headers=self.headers) r.raise_for_status() r.encoding = r.apparent_encoding opt = self.is_login(r.text) if opt == 1: print("登录成功") elif opt == 2: print("用户名和密码错误") else: print("验证码错误") return opt == 1 # print(s.cookies.get_dict()) # print(r.text) except: print(r.text) print("登录失败", r.status_code) return False finally: print("********************************")
def login(self, username=None, password=None): ''' return a status code. 0: login successfully 1: wrong username 2: wrong password -1: network is unreachable !NOTICE: username and password MUST be provided the first time ''' if username is not None: self.userInfo = { "username": username, "password": password, "captcha": "" } captchaUrl = self.url + "simpleCaptcha/captcha" loginUrl = self.url + "auth/signIn" while True: try: captchaImg = self.session.get(captchaUrl) self.userInfo["captcha"] = captcha(captchaImg.content) res = self.session.post(url=loginUrl, data=self.userInfo) except requests.exceptions.ConnectionError, e: print e return -1 if self.loginStatusCheck(res): return 0 msg = re.findall('showmsg."(.*)",', res.text) if msg: msg = msg[0] print msg if msg == u"登录失败: 用户不存在": return 1 elif msg == u"登录失败: 密码不正确": return 2
def test_002(self): print("Style 2 Test:") for example in examples2: print("Input: {} - expect {}".format(example[0], example[1])) test = captcha(example[0], 2) self.assertEqual(test, example[1])
def test_3_captcha(): input = "1234" expected_output = 0 assert captcha(input) == expected_output
def test_captcha4(self): result = captcha("91212129") self.assertEqual(9, result)
def test_captcha5(self): result = captcha("1234xx") self.assertEqual(0, result)
def test_2_captcha(): input = "1111" expected_output = 4 assert captcha(input) == expected_output
def test_captcha6(self): result = captcha("11221") self.assertEqual(4, result)
def test_1_captcha(): input = "1122" expected_output = 3 assert captcha(input) == expected_output
def test_solve_puzzle_captcha(): input = open('./day01/puzzle_input.txt', 'r').read() expected_output = 1089 assert captcha(input) == expected_output
def test_4_captcha(): input = "91212129" expected_output = 9 assert captcha(input) == expected_output
def test_captcha7(self): result = captcha("111") self.assertEqual(3, result)
def test_captcha1(self): result = captcha("1122") self.assertEqual(3, result)