The pam_google_authenticator module is designed to protect user authentication with a second factor, either time-based (TOTP) or counter-based (HOTP). PAM module for Google two-factor authentication Synopsis func sha1Hash ( msg : openArray ): seq = mapIt ( ( Sha1Digest ( secureHash ( msg ))), char ( it )) func `xor` ( s : seq val : byte ): seq = # Apply a XOR to the chars of a sequence. hash : HashFunc # Hash algorithm used with HMAC. baseTime : Time # The start time for TOTP step calculation. timeStep : Duration # Length of each time step for TOTP. Import endians, math, sequtils, std / sha1, times type HashFunc = proc ( msg : openArray ): seq OneTimePassword = object digit : int # Length of code generated. ) end for i in 1 : 7 println ( genotp ( "JBSWY3DPEHPK3PXP" )) sleep ( 15 ) end ) secret = transcode ( Base32Decoder (), secret32 ) return genotp ( secret kwargs. = 0 end return hashfunction ()]) end #see also hmac ( hashfunc, bs = 64 ) = ( key, msg, blocksize = bs ) -> hmac ( key, msg, hashfunc, blocksize ) function genotp ( secret :: String tokenlength = 6, hashfunc = hmac ( sha1 ), tim = time () / 30, outbase = 10 ) message = (()) msghash = hashfunc ( secret, message ) offset = msghash & 0x0f binary = ( Int ( msghash & 0x7f ) << 24 ) | ( Int ( msghash & 0xff ) << 16 ) | ( Int ( msghash & 0xff ) << 8 ) | ( msghash & 0xff ) otp = binary % outbase ^ tokenlength string ( otp, pad = tokenlength, base = outbase ) end function genopt_fromb32 ( secret32 kwargs. Using CodecBase using SHA function hmac ( key, msg, hashfunction, blocksize = 64 ) key = hashfunction ( key ) paddingneeded = blocksize - length ( key ) if paddingneeded > 0 resize! ( key, blocksize ) key. Using System using namespace RosettaTOTP
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |