#! /usr/bin/env python # -*- coding: utf-8 -*- try :import pswd_cfg except :pass class Pswdgen( object ): """ パスワード生成クラス """ def get_pswd( self, myname, usrname, url, length ): """ パスワードの取得 """ netloc = self.get_netloc( url ) hexpswd = self.get_hexpswd( ( myname, usrname, netloc ), length ) return self.hexstr2word( hexpswd ) def hexstr2word( self, hexstr ): """ 16進数表示の文字列からその番号に対応する文字列を取得 """ import string words = string.digits + string.ascii_letters words_len = len( words ) rstr = '' for ii in range( 0, len( hexstr ), 2 ): num = int( '0x' + hexstr[ ii:ii+2], 16 ) rstr += words[ num % words_len ] return rstr def get_hexpswd( self, datas, length ): """please orver ride""" pass def get_netloc( self, url ): """ urlからノード名を取得 """ import urlparse return urlparse.urlparse( url )[1] class Finished( Exception ):pass class UI_console( Pswdgen ): def __init__( self ): print 'please input date; myname, usrname, url, length' self.exqt() def exqt( self ): myname = raw_input( 'myname :%12s :'%( pswd_cfg.DFLT_MYNAME ) ) usrname = raw_input( 'usrname :%12s :'%( pswd_cfg.DFLT_USRNAME ) ) url = raw_input( 'url :%12s :'%( pswd_cfg.DFLT_URL ) ) length = input( 'length :%12s :'%( pswd_cfg.DFLT_LENGTH ) ) pswd = self.get_pswd( myname, usrname, url, length ) while True:raw_input( pswd ) try: import Tkinter as TK class UI_Tkinter( TK.Frame, Pswdgen ): def __init__( self ): TK.Frame.__init__( self, master=None ) self.pack() self.master.title( 'pswdgen' ) self.entries = {} self.mk_widgets() def labeled_entry( self, name ): frame = TK.Frame() TK.Label( frame, text=name, width=10 ).pack( side='left' ) self.entries[name] = TK.Entry( frame ) self.entries[name].pack( side='right' ) return frame def mk_widgets( self ): self.labeled_entry( 'myname' ).pack() self.labeled_entry( 'usrname' ).pack() self.labeled_entry( 'url' ).pack() self.labeled_entry( 'length' ).pack() frame = TK.Frame() self.EXQT = TK.Button( frame, text='EXQT', command=self.exqt ) self.EXQT.pack( side='left', fill=TK.X, expand=1 ) self.QUIT = TK.Button( frame, text='QUIT', command=self.quit ) self.QUIT.pack( side='left', fill=TK.X, expand=1 ) frame.pack( fill=TK.X ) self.labeled_entry( 'password' ).pack() #default value self.entries[ 'myname' ].insert( 0, pswd_cfg.DFLT_MYNAME ) self.entries[ 'usrname' ].insert( 0, pswd_cfg.DFLT_USRNAME ) self.entries[ 'url' ].insert( 0, pswd_cfg.DFLT_URL ) self.entries[ 'length' ].insert( 0, pswd_cfg.DFLT_LENGTH ) def exqt( self ): myname = self.entries[ 'myname' ].get() usrname = self.entries[ 'usrname' ].get() url = self.entries[ 'url' ].get() length = int( self.entries['length'].get() ) pswd = self.get_pswd( myname, usrname, url, length ) self.entries[ 'password' ].delete( 0, TK.END ) self.entries[ 'password' ].insert( 0, pswd ) except ImportError:pass class Main( object ): def __init__( self ): self.choiseUI() def choiseUI( self ): try: try:TK except NameError:pass else: runner = UI_Tkinter() runner.mainloop() runner.destroy() raise Finished UI_console() except Finished:pass if __name__ == '__main__': Main()
2011年11月4日金曜日
パスワードの生成
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿