python密码字典库_利用python在Oracle数据库中生成密码字典库

importdatetimeimportgcimportosfrom conf importdb_config_dba,logconfdeftimecost(func):def inner(*args, **kwargs):

starttime=datetime.datetime.now()

func_name= str(func).split(' ')[1]#logger.info('Start doing %s ', func_name)

logger.info('Start doing %s and detail parameter: %s', func_name,(args or kwargs or ('No parameter')))

result= func(*args, **kwargs)#func_name = str(func).split(' ')[1]

#logger.info('%s done', func_name)

logger.info('Execute {} using times: {}s'.format(func_name, datetime.datetime.now() -starttime))

logger.info("%s is done successfully with detail parameter: %s '\n'", func_name,(args or kwargs or ('No parameter')))returnresultreturninner

@timecostdef threefor(name='get three length password library'):

three=[]for key1 inword:for key2 inword:for key3 inword:

three.append({'wordkey': key1 + key2 +key3})returnthree

@timecostdef getword(name='get password character sets'):

lowercase= 'abcdefghijklmnopqrstuvwxyz'uppercase= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'digits= '0123456789'special= """!"#$%&'( )*+,-./:;<=>?@[]^_`{|}~"""word= lowercase + uppercase + digits +special

logger.info('word content is: %s and total with %d', word,len(word))returnword

@timecostdefexecutesql(sql):try:

cursor.execute(sql)exceptException:

logger.error('Faild to execute %s', sql,exc_info=True)else:#logger.info("Execute %s successfully", sql)

pass@timecostdef executemanysql(name='executemany'):try:

logger.info('Start batch execute %s',sql)

cursor.executemany(sql,threefor())exceptException:

logger.error('Faild to batch execute %s', sql,exc_info=True)else:pass@timecostdef sqlcommit(name='commit sql in this module'):try:

db.commit()exceptException:

logger.error("Faild to commit: %s", sql, exc_info=True)else:pass@timecostdef condb(name="connect to oracle database"): #create oracle db connection

try:

db=db_config_dba.conexceptException:

logger.error('Faild to gconnection to oracle Database', exc_info=True)else:

cursor=db.cursor()returndb,cursor

@timecostdefclosedb():try:

cursor.close()

db.close()exceptException :

logger.error('Faild to gconnection to oracle Database', exc_info=True)if __name__ == "__main__":

gc.collect()

logtarget= os.path.basename(__file__).split('.')[0]

logger= logconf.logconf(logtarget) #init log config

word = getword() #get password character set

db,cursor=condb() #connect to oracle db

sql= 'drop table librarykey purge'executesql(sql)

sql= 'create table librarykey ( wordkey varchar(20),CONSTRAINT work_key primary key (wordkey))'executesql(sql)

sql= 'insert into librarykey (wordkey) values (:wordkey)'executemanysql(sql)#verfication the key number's as the sql result is tuple, so we should use row[0]

sql = 'select count(*) from librarykey'executesql(sql)for threekey incursor:

threekey[0]if threekey[0] == len(word)*len(word)*len(word):

logger.info('total password number should be %d:',threekey[0])

sqlcommit()else:print("not all the password is generate,pls try again")

logger.error('password library set in oracle db is failed', exc_info=True)

closedb()

gc.collect()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值