<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
(1)模擬登陸介面,判別使用者名稱和密碼,給出合適的提示,如果超過三次,鎖定輸入。用代替密碼;或者最新輸入顯示,前面的變成;安全性措施。
(2)同時新增如下圖的加強驗證(京東)。
(3)在觸動卷軸時再出現空缺位置。
拓展:
滾軸驗證就是將滾軸的移動和圖片小塊的移動相繫結,在滾軸鬆開時觸發相對應的檢查函數,為了有一定的容錯率,設定滾軸的位置與設定的位置相差3個畫素以內即算驗證成功。
登入主介面:
登入驗證:
def check_login_func(self): if not self.validate_line.text(): QMessageBox.warning(self, "警告", "還未輸入驗證碼") return validate_slide = Validate_page() r = validate_slide.exec_() if not r: return if self.validate.upper() == self.validate_line.text().upper(): if USER_PWD.get(self.user_line.text()) == self.pwd_line.text(): QMessageBox.information(self, 'Information', 'Log in Successfully!') self.nums = 0 self.refresh() # self.close() # self.STU.exec() else: QMessageBox.critical(self, 'Wrong', 'Wrong Username or Password!') self.nums = self.nums + 1 if self.nums == 3: QMessageBox.critical(self, "wrong", "密碼輸錯次數已達三次!") self.close() self.user_line.clear() self.pwd_line.clear() self.validate_line.clear() else: QMessageBox.critical(self, "wrong", "驗證碼輸入有誤!") self.refresh() self.validate_line.clear()
自動生成驗證碼圖片:
def get_chars(): """生成給定長度的字串,返回列表格式""" return random.sample(chars, length) def create_lines(): """繪製干擾線""" line_num = random.randint(*n_line) # 干擾線條數 for i in range(line_num): # 起始點 begin = (random.randint(0, size[0]), random.randint(0, size[1])) # 結束點 end = (random.randint(0, size[0]), random.randint(0, size[1])) draw.line([begin, end], fill=(0, 0, 0)) def create_points(): """繪製干擾點""" chance = min(100, max(0, int(point_chance))) # 大小限制在[0, 100] for w in range(width): for h in range(height): tmp = random.randint(0, 100) if tmp > 100 - chance: draw.point((w, h), fill=(0, 0, 0)) def create_strs(): """繪製驗證碼字元""" c_chars = get_chars() strs = ' %s ' % ' '.join(c_chars) # 每個字元前後以空格隔開 font = ImageFont.truetype(font_type, font_size) font_width, font_height = font.getsize(strs) draw.text(((width - font_width) / 3, (height - font_height) / 3), strs, font=font, fill=fg_color) return ''.join(c_chars) if draw_lines: create_lines() if draw_points: create_points() strs = create_strs() # 圖形扭曲引數 params = [1 - float(random.randint(1, 2)) / 100, 0, 0, 0, 1 - float(random.randint(1, 10)) / 100, float(random.randint(1, 2)) / 500, 0.001, float(random.randint(1, 2)) / 500 ] img = img.transform(size, Image.PERSPECTIVE, params) # 建立扭曲 img = img.filter(ImageFilter.EDGE_ENHANCE_MORE) # 濾鏡,邊界加強(閾值更大) mstream = io.BytesIO() img.save(mstream, img_type) if save_img: img.save("validate.jpg", img_type) return mstream, strs
註冊介面部分:
頁面初始化:
def __init__(self): super(SigninPage, self).__init__() self.signin_user_label = QLabel('Username:', self) self.signin_pwd_label = QLabel('Password:', self) self.signin_pwd2_label = QLabel('Password:', self) self.signin_user_line = QLineEdit(self) self.signin_pwd_line = QLineEdit(self) self.signin_pwd2_line = QLineEdit(self) self.signin_button = QPushButton('Sign in', self) self.user_h_layout = QHBoxLayout() self.pwd_h_layout = QHBoxLayout() self.pwd2_h_layout = QHBoxLayout() self.all_v_layout = QVBoxLayout() self.lineedit_init() self.pushbutton_init() self.layout_init() def layout_init(self): self.user_h_layout.addWidget(self.signin_user_label) self.user_h_layout.addWidget(self.signin_user_line) self.pwd_h_layout.addWidget(self.signin_pwd_label) self.pwd_h_layout.addWidget(self.signin_pwd_line) self.pwd2_h_layout.addWidget(self.signin_pwd2_label) self.pwd2_h_layout.addWidget(self.signin_pwd2_line) self.all_v_layout.addLayout(self.user_h_layout) self.all_v_layout.addLayout(self.pwd_h_layout) self.all_v_layout.addLayout(self.pwd2_h_layout) self.all_v_layout.addWidget(self.signin_button) self.setLayout(self.all_v_layout) def lineedit_init(self): self.signin_user_line.setPlaceholderText("username") self.signin_pwd_line.setPlaceholderText("password") self.signin_pwd2_line.setPlaceholderText("password again") self.signin_pwd_line.setEchoMode(QLineEdit.Password) self.signin_pwd2_line.setEchoMode(QLineEdit.Password) self.signin_user_line.textChanged.connect(self.check_input_func) self.signin_pwd_line.textChanged.connect(self.check_input_func) self.signin_pwd2_line.textChanged.connect(self.check_input_func)
註冊檢驗部分:
def check_signin_func(self): if self.signin_pwd_line.text() != self.signin_pwd2_line.text(): QMessageBox.critical(self, 'Wrong', 'Two Passwords Typed Are Not Same!') elif self.signin_user_line.text() not in USER_PWD: USER_PWD[self.signin_user_line.text()] = self.signin_pwd_line.text() QMessageBox.information(self, 'Information', 'Register Successfully') self.close() else: QMessageBox.critical(self, 'Wrong', 'This Username Has Been Registered!') self.signin_user_line.clear() self.signin_pwd_line.clear() self.signin_pwd2_line.clear()
滾軸驗證部分:
class Validate_page(QDialog): def __init__(self): super(Validate_page, self).__init__() self.resize(600, 500) self.setWindowTitle("拖動滾軸驗證") self.initUI() self.Widget_init() self.refresh() # self.show() def initUI(self): # 初始化相關控制元件位置 self.lb_bg = QLabel(self) self.lb_sl = QLabel(self) self.lb_bg.setStyleSheet("border: 2px solid red") # self.lb_sl.setStyleSheet("border: 2px solid blue") self.lb_bg.setGeometry(100, 100, 400, 200) self.lb_wz = QLabel(self) # self.lb_wz.setStyleSheet("border: 2px solid green") self.refresh() self.button = QPushButton("取消", self) self.button.setGeometry(400, 430, 100, 50) self.slider = QSlider(Qt.Horizontal, self) self.slider.setGeometry(100, 350, 400, 50) def Widget_init(self): # 初始化相關元件的訊號連線 self.slider.setMinimum(0) self.slider.setMaximum(360) self.slider.valueChanged.connect(self.slide) self.slider.sliderReleased.connect(self.check) self.button.clicked.connect(self.cancel) def slide(self, value): self.lb_sl.move(100 + value, self.answer_y) # 將滾軸與圖片小塊繫結 # print(value) def refresh(self): import random # 隨機生成驗證區域 self.answer_x = random.randint(100, 460) self.answer_y = random.randint(100, 260) pic = random.randint(0, 14) self.lb_sl.setGeometry(100, self.answer_y, 40, 40) self.lb_wz.setGeometry(self.answer_x, self.answer_y, 40, 40) img = cv2.imread(f"pic/{pic}.jpeg") # 讀取背景圖片 img = cv2.resize(img, (400, 200)) x = self.answer_x - 100 y = self.answer_y - 100 img1 = copy.copy(img[y:y + 40, x:x + 40]) # 扣40*40的圖片小塊 img[y:y + 40, x:x + 40] = 255 # 將被扣區域置為白色 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB) qt_img = QImage(img.data, 400, 200, QImage.Format_RGB888) qt_img1 = QImage(img1.data, 40, 40, QImage.Format_RGB888) self.lb_bg.setPixmap(QPixmap.fromImage(qt_img)) self.lb_sl.setPixmap(QPixmap.fromImage(qt_img1)) def check(self): # 檢驗滑動驗證是否成功 # 獲取設定區域座標 x = self.lb_sl.pos().x() y = self.lb_sl.pos().y() print(f"({x},{y})") if abs(x - self.answer_x) <= 3: # 容錯為3px QMessageBox.information(self, "恭喜", "驗證成功") self.done(1) else: QMessageBox.critical(self, "錯誤", "驗證失敗") self.slider.setValue(0) self.refresh() def cancel(self): self.done(0) # 點選取消滑動驗證
執行結果
全部背景圖片:
註冊介面:
到此這篇關於python 密碼驗證(滾軸驗證)的文章就介紹到這了,更多相關python 密碼驗證(滾軸驗證)內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45