隨機生成200個8位驗證碼,並存入mysql資料庫
生成200個8位的驗證碼
# -*- coding: utf-8 -*- import mysql.connector import random,string def readkey(num,length): with open('C:/Users/Administrator/Desktop/randomnum.txt', 'w+') as fo: for i in range(num): chars = string.ascii_letters + string.digits s = [random.choice(chars) for i in range(length)] fo.write(''.join(s) + '\n') with open('C:/Users/Administrator/Desktop/randomnum.txt', 'r') as fo: keylist = fo.readlines() return keylist def storeinMysql(keylist): try: # 連線資料庫 conn = mysql.connector.connect(user='root', password='password', db = 'mysql') cursor = conn.cursor() except BaseException as e: print('connection failed ') else: try: # 若沒有database randnum,則建立一個名為randnum的database cursor.execute('create database if not exists randnum') cursor.execute('use randnum') # 若沒有表,則建立一個名為randkey的表,包含randkey和name兩個欄位 cursor.execute('''create table if not exists randkey3( keynum varchar(20) primary key,name varchar(20))''') for line in keylist: # print (line) cursor.execute('insert into randkey3 (keynum,name) values (%s, %s)', [line, 'cathy']) conn.commit() except BaseException as e: print(e) finally: cursor.close() conn.close() if __name__ == '__main__': storeinMysql(readkey(200,8))
在生成驗證碼的時候,可以使用uuid4,直接生成list,這樣不用存檔案,更簡潔
轉自github的ilcyb的答案
import uuid
def generateActivationCode(num): codeList = [] for i in range(num): code = str(uuid.uuid4()).replace('-','').upper() while code in codeList: code = str(uuid.uuid4()).replace('-','').upper() codeList.append(code) return codeList
fo.write(''.join(s) + '\n')
由於s取出來為一個list,需要用join函式,以''連線起來
相關推薦
隨機生成200個8位驗證碼,並存入mysql資料庫
生成200個8位的驗證碼# -*- coding: utf-8 -*- import mysql.connector import random,string def readkey(num,length): with open('C:/Users/Administ
#在26個大小寫字母(52個),以及9個數字組成的字符列表中,隨機生成10個8位密碼
code app pri spa [] range 小寫 bsp clas print(ord(‘A‘)) print(ord(‘a‘)) print(ord(‘0‘)) import random SecChar=[] for
java讀取mongoDB某個資料庫的集合的指定欄位值,並存入mysql資料庫指定表中
1、查詢mongodb單個欄位的所有值內容:db.getCollection('amac').find({},{"managerName":1,"_id":0}) //PS:"_id":0表示不顯示id值 java: //mongoDB資料讀取,存入MYSQL資料庫
Python隨機生成一個六位數的驗證碼
import random str = "" str1 = "" list = [] index = 0 num = 0 while num < 6: x = random.choice(range(12)) # 對隨機生成的字元進行隨機排序 if
自定義 iOS 密碼框或驗證碼輸入框,支援多位驗證碼,4位或6位驗證碼自己選擇。
密碼框 樣式 自定義輸入驗證碼樣式 git地址: https://github.com/HSFGitHub/CodeInputView.git 支援全部自定義 ,幾位驗證碼的變化,輸入樣式,
js把頁面明細行資料多個欄位組成陣列,並獲取某個欄位值最大和其次大的資料賦值到文字框;
要求:前臺新增頁面的明細行中,有列下拉框選擇分類和一列付款金額的輸入框,明細行上面有兩個輸入框,要求在明細行選擇的分類和付款金額中篩選付款金額之和第一高的的分類和金額、第二高的分類和金額自動複製到上面的兩個輸入框中; 思路:迴圈明細表,把所有的明細表的分類和付款金額放到json陣列中,然後迴圈j
隨機生成(x,y)資料值,並畫出散點圖
隨機生成(x,y)資料值,並畫出散點圖 import numpy as np import matplotlib.pyplot as plt r = []#生成兩個空列表 b = [] d=np.zeros((50,2)) print(d) Mean=0 STD=5 for i in r
SSM框架下登入頁面,圖片驗證碼,密碼加密對比資料庫資料(二)
登入頁面的Controller的程式碼如下: 在這過程中,需要對填入資料進行判斷,是否為使用者名稱存在?是否密碼有誤?是否驗證碼有誤?如若都沒有錯誤則頁面跳轉至登入成功頁面。 @RequsetMapper("/login.do") public @Respons
取redis中手機驗證碼,並驗證是否正確
controller: /** * 校驗驗證碼是否正確 * @param smsCode * @param phone */ @RequestMapping(value = "checkSmsCode",method = RequestMethod.POST) public Result
Python 批量下載驗證碼圖片及切割驗證碼圖片,識別驗證碼,並以識別的文字重命令驗證碼
1、Python 批量下載驗證碼圖片 2、批量切割驗證碼圖片 3、識別驗證碼,並以識別的文字重命令驗證碼 #!C:/Python27 #coding=utf-8 import pytesseract from pytesser import * from PIL imp
呼叫簡訊介面傳送驗證碼,並對驗證碼進行驗證
首先需要對簡訊介面內容進行封裝: public class SendMsg2Util { private static String url="http://gw.api.taobao.com/router/rest"; private static Str
Python3.4---實戰專案-自動下載圖片驗證碼,並儲存到專門資料夾,使用圖片驗證碼庫識別,然後打印出來
Python3.4—實戰專案-自動下載圖片驗證碼,並儲存到專門資料夾,使用圖片驗證碼庫識別,然後打印出來 1、環境部署 參考文章《使用Python識別圖片驗證碼》內容,製造好圖片驗證碼識別庫msweb1.dat 1.1、對圖片驗證碼隨時下載的URL地址
python隨機生成四位驗證碼
pythonimport random check=‘‘ for num in range(4): i = random.randrange(1,3) #隨機生成1或者2 if i%2==0: #判斷
PHP 使用陣列隨機生成4位驗證碼
我們要生成4位隨機驗證碼,首先要在A-Z,a-z,0-9之間隨機產生4位。此時我們會用到一個函式range(),這個函式是建立一個包含指定範圍單元的陣列,返回型別為陣列。程式碼如下: <?php $arr1 = range('a','z'); $arr2 = range('A','Z')
隨機生成6位驗證碼或密碼(字母和數字組合)
import java.util.Random; public class Test { public static char[] getChar(){ char[] passwordLit = new char[62]; cha
每天一個小程式——第 0001 題:生成200個驗證碼
# -*- coding: utf-8 -*- """ 第 0001 題:做為 Apple Store App 獨立開發者,你要搞限時促銷,為你的應用生成啟用碼(或者優惠券),使用 Python
Python隨機數random模塊學習,並實現生成6位驗證碼
import ID for循環 list 序列 獲取 大小 前言 字符 一、前言 學習python隨機數random模塊的使用 ,並使用模塊中的函數,實現6位驗證碼生成 二、random模塊 1、random.random() 返回0-1直接的隨機數,類型為float &g
隨機n 位驗證碼
第一種純數字六位驗證碼 import randomdef get_code(n=6): s = '' for i in range(n): num = random.randint(0,9) s+=str(num) return sret=get_code()p
time-based基於google key生成6位驗證碼(google authenticator)
input div 如果 multipl turn 啟用 struct highlight time 由於公司服務器啟用了雙因子認證,登錄時需要再次輸入谷歌身份驗證器生成的驗證碼。而生成驗證碼是基於一套固定的算法的,以當前時間為基礎,基於每個人的google key去生成一
【python學習】生成200個兌換碼
# coding UTF-8 import random words = [] keys = [] # 生成字元列表 for i in range(0,10): words.append(st