OTP Two Factor Authentication( 2FA ) Using PowerBuilder
Source Code Example
nvo_authenticator from nonvisualobject
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
forward global type nvo_authenticator from nonvisualobject end type type time_zone_information from structure within nvo_authenticator end type type systemtime from structure within nvo_authenticator end type type hmac_info from structure within nvo_authenticator end type end forward type time_zone_information from structure long bias long standardname[31] systemtime standarddate long standardbias long daylightname[31] systemtime daylighttime long daylightbias end type type systemtime from structure integer wyear integer wmonth integer wdayofweek integer wday integer whour integer wminute integer wsecond integer wmilliseconds end type type hmac_info from structure unsignedlong hashalgid unsignedlong pbinnerstring unsignedlong cbinnerstring unsignedlong pbouterstring unsignedlong cbouterstring end type global type nvo_authenticator from nonvisualobject autoinstantiate end type type prototypes Function ulong GetTimeZoneInformation (ref TIME_ZONE_INFORMATION lpTimeZoneInformation) Library "kernel32" Function boolean TzSpecificLocalTimeToSystemTime(TIME_ZONE_INFORMATION lpTimeZone, SYSTEMTIME lpLocalTime, ref SYSTEMTIME lpUniversalTime) Library "kernel32" Function String GetBase32Encode(String msg) Library "BaseEncoding.dll" Alias For "GetBase32Encode;Ansi" Function String GetBase32Decode(String coded) Library "BaseEncoding.dll" Alias For "GetBase32Decode;Ansi" Function String GetBase64Encode(String msg) Library "BaseEncoding.dll" Alias For "GetBase64Encode;Ansi" Function String GetBase64Decode(String coded) Library "BaseEncoding.dll" Alias For "GetBase64Decode;Ansi" Function ulong GetLastError () Library "kernel32.dll" Function ulong FormatMessage( ulong dwFlags, ulong lpSource, ulong dwMessageId, ulong dwLanguageId, Ref string lpBuffer, ulong nSize, ulong Arguments ) Library "kernel32.dll" Alias For "FormatMessageW" Function boolean CloseHandle ( long hObject ) Library "kernel32.dll" Function boolean TzSpecificLocalTimeToSystemTime ( long lpTimeZoneInformation, SYSTEMTIME lpLocalTime, Ref SYSTEMTIME lpUniversalTime ) Library "kernel32.dll" Function boolean CryptBinaryToString ( blob pbBinary, ulong cbBinary, ulong dwFlags, Ref string pszString, Ref ulong pcchString ) Library "crypt32.dll" Alias For "CryptBinaryToStringW" Function boolean CryptBinaryToString ( blob pbBinary, ulong cbBinary, ulong dwFlags, long pszString, Ref ulong pcchString ) Library "crypt32.dll" Alias For "CryptBinaryToStringW" Function boolean CryptStringToBinary ( string pszString, ulong cchString, ulong dwFlags, Ref blob pbBinary, Ref ulong pcbBinary, Ref ulong pdwSkip, Ref ulong pdwFlags ) Library "crypt32.dll" Alias For "CryptStringToBinaryW" Function ulong BCryptCloseAlgorithmProvider ( Ref long hAlgorithm, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptCreateHash ( long hAlgorithm, Ref long phHash, Ref blob pbHashObject, ulong cbHashObject, long pbSecret, ulong cbSecret, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptCreateHash ( long hAlgorithm, Ref long phHash, Ref blob pbHashObject, ulong cbHashObject, blob pbSecret, ulong cbSecret, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptDestroyHash ( Ref long hHash ) Library "bcrypt.dll" Function ulong BCryptFinishHash ( long hHash, Ref blob pbOutput, ulong cbOutput, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptGenRandom ( long phAlgorithm, Ref long pbBuffer, ulong cbBuffer, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptGetProperty ( long hObject, string pszProperty, Ref long pbOutput, ulong cbOutput, Ref ulong pcbResult, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptHashData ( long hHash, blob pbInput, ulong cbInput, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptOpenAlgorithmProvider ( Ref long phAlgorithm, string pszAlgId, ulong pszImplementation, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptGenerateSymmetricKey ( long phAlgorithm, Ref long phKey, Ref blob pbKeyObject, ulong cbKeyObject, blob pbSecret, ulong cbSecret, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptDestroyKey ( Ref long hKey ) Library "bcrypt.dll" Function ulong BCryptEncrypt ( long hKey, blob pbInput, ulong cbInput, long pPaddingInfo, blob pbIV, ulong cbIV, long pbOutput, ulong cbOutput, Ref ulong pcbResult, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptEncrypt ( long hKey, blob pbInput, ulong cbInput, long pPaddingInfo, blob pbIV, ulong cbIV, Ref blob pbOutput, ulong cbOutput, Ref ulong pcbResult, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptDecrypt ( long hKey, blob pbInput, ulong cbInput, long pPaddingInfo, blob pbIV, ulong cbIV, long pbOutput, ulong cbOutput, Ref ulong pcbResult, ulong dwFlags ) Library "bcrypt.dll" Function ulong BCryptDecrypt ( long hKey, blob pbInput, ulong cbInput, long pPaddingInfo, blob pbIV, ulong cbIV, Ref blob pbOutput, ulong cbOutput, Ref ulong pcbResult, ulong dwFlags ) Library "bcrypt.dll" FUNCTION Long CreateBmpFile(string fileName, string text, long errCorLvl, long borderSize, long scale) LIBRARY "QRCodeGenLibrary.dll" end prototypes type variables Private: // BCrypt Error Codes Constant ULong STATUS_SUCCESS = 0 // 0x00000000 Constant ULong STATUS_BUFFER_TOO_SMALL = 3221225507 // 0xC0000023 Constant ULong STATUS_INVALID_BUFFER_SIZE = 3221225990 // 0xC0000206 Constant ULong STATUS_INVALID_HANDLE = 3221225480 // 0xC0000008 Constant ULong STATUS_INVALID_PARAMETER = 3221225485 // 0xC000000D Constant ULong STATUS_NO_MEMORY = 3221225495 // 0xC0000017 Constant ULong STATUS_NOT_FOUND = 3221226021 // 0xC0000225 Constant ULong STATUS_NOT_SUPPORTED = 3221225659 // 0xC00000BB // Cryptography Primitive Property Identifiers Constant String BCRYPT_BLOCK_LENGTH = "BlockLength" Constant String BCRYPT_OBJECT_LENGTH = "ObjectLength" Constant String BCRYPT_HASH_LENGTH = "HashDigestLength" Constant ULong BCRYPT_ALG_HANDLE_HMAC = 8 Constant ULong BCRYPT_BLOCK_PADDING = 1 Constant ULong NULL = 0 Constant ULong CRYPT_STRING_BASE64 = 1 Constant ULong CRYPT_STRING_HEXRAW = 12 Constant Ulong CRYPT_STRING_NOCRLF = 1073741824 // 0x40000000 // constants for CreateFile API function Constant Long INVALID_HANDLE_VALUE = -1 Constant ULong GENERIC_READ = 2147483648 Constant ULong GENERIC_WRITE = 1073741824 Constant ULong FILE_SHARE_READ = 1 Constant ULong FILE_SHARE_WRITE = 2 Constant ULong CREATE_NEW = 1 Constant ULong CREATE_ALWAYS = 2 Constant ULong OPEN_EXISTING = 3 Constant ULong OPEN_ALWAYS = 4 Constant ULong TRUNCATE_EXISTING = 5 long il_hAlg long il_hRanAlg long il_hHash long il_hKey Public: // CNG Algorithm Identifiers // Hashing Algorithms Constant String BCRYPT_MD2_ALGORITHM = "MD2" Constant String BCRYPT_MD4_ALGORITHM = "MD4" Constant String BCRYPT_MD5_ALGORITHM = "MD5" Constant String BCRYPT_SHA1_ALGORITHM = "SHA1" Constant String BCRYPT_SHA256_ALGORITHM = "SHA256" Constant String BCRYPT_SHA384_ALGORITHM = "SHA384" Constant String BCRYPT_SHA512_ALGORITHM = "SHA512" // Encryption Algorithms Constant String BCRYPT_AES_ALGORITHM = "AES" Constant String BCRYPT_DES_ALGORITHM = "DES" Constant String BCRYPT_DESX_ALGORITHM = "DESX" Constant String BCRYPT_RC2_ALGORITHM = "RC2" Constant String BCRYPT_3DES_ALGORITHM = "3DES" Constant String BCRYPT_3DES_112_ALGORITHM = "3DES_112" Constant ULong STATUS_USER_ERROR = 0 // public non-constant instance variables String LastFunction String LastErrText ULong LastErrCode Encoding iEncoding = EncodingAnsi! end variables forward prototypes public function integer longtobytearray (long al_data, ref byte a_data[]) public function byte bitwiseand (byte a_value1, byte a_value2) public function long getunixepoch () public function integer of_copylongtobytes (long al_long, ref byte a_byte[4]) public function blob of_blob (byte a_byte[]) private subroutine of_finalcleanup () public function unsignedlong of_getlasterror (ref string as_msgtext) private subroutine of_errorcleanup (string as_function) private function boolean nt_success (unsignedlong ntstatus) public function blob of_hmac (string as_algorithm, blob ablb_message, blob ablb_secret) public function long get_qrcode_bitmap (string as_filename, string as_text, long al_errcorlvl, long al_bordersize, long al_scale) public function long get_qrcode_bitmap (string as_filename, string as_text) public function string generatepin (string key, boolean ab_keytypebase32) public function string generatepin (string as_key, long counter, boolean ab_keytypebase32) public function string generateprovisioningimage (string identifier, string as_key, boolean ab_keytypebase32) end prototypes public function integer longtobytearray (long al_data, ref byte a_data[]);//==================================================================== // Function: nvo_authenticator.longtobytearray() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value long al_data // reference byte a_data[] //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.longtobytearray ( long al_data, ref byte a_data[] ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== byte l_data[4] Long l_len = 4 Integer i, j of_copylongtobytes ( al_data, l_data ) //pad with 4 zeros For i = 1 To 4 j = UpperBound(a_data) +1 a_data[j] = 0 Next //Copy over data in inverse order For i = 4 To 1 Step -1 j = UpperBound (a_data) + 1 a_data[j] = l_data[i] Next Return 1 end function public function byte bitwiseand (byte a_value1, byte a_value2);//==================================================================== // Function: nvo_authenticator.bitwiseand() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value byte a_value1 // value byte a_value2 //-------------------------------------------------------------------- // Returns: byte //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.bitwiseand ( byte a_value1, byte a_value2 ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer li_i Byte lbyte_result, lbyte_factor lbyte_result = 0 For li_i = 1 To 8 If a_value1 = 0 Or a_value2 = 0 Then Exit If li_i = 1 Then lbyte_factor = 1 Else lbyte_factor *= 2 End If If Mod(a_value1, 2) = 1 And Mod(a_value2, 2) = 1 Then lbyte_result += lbyte_factor End If a_value1 /= 2 a_value2 /= 2 Next Return lbyte_result end function public function long getunixepoch ();//==================================================================== // Function: nvo_authenticator.getunixepoch() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: long //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.getunixepoch ( ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long days Long seconds Long epoch ULong rc1 Boolean rc2 TIME_ZONE_INFORMATION tzi SYSTEMTIME local SYSTEMTIME utc DateTime l_datetime_utc rc1 = GetTimeZoneInformation(tzi) //Convert PowerBuilder datetime to SYSTEMTIME local.wYear = Year(Today()) local.wMonth = Month(Today()) local.wDay = Day(Today()) local.wHour = Hour(Now()) local.wMinute = Minute(Now()) local.wSecond = Second(Now()) local.wMilliseconds = 0 //Get the time in UTC rc2 = TzSpecificLocalTimeToSystemTime(tzi, local, utc) //Convert the UTC SYSTEMTIME back to a PowerBuilder datetime l_datetime_utc = DateTime ( Date ( utc.wYear, utc.wMonth, utc.wDay ), Time ( utc.wHour, utc.wMinute, utc.wSecond ) ) days = DaysAfter ( Date ( '1970/01/01' ), Date ( l_datetime_utc ) ) seconds = SecondsAfter ( Time ( '00:00:00' ), Time ( l_datetime_utc ) ) epoch = ( days * 24 * 60 * 60 ) + seconds Return epoch end function public function integer of_copylongtobytes (long al_long, ref byte a_byte[4]);//==================================================================== // Function: nvo_authenticator.of_copylongtobytes() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value long al_long // reference byte a_byte[4] //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.of_copylongtobytes ( long al_long, ref byte a_byte[4] ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long ll_long Integer i = 1, j, li_byte[] ll_long = al_long Do While Truncate(ll_long / 256, 0) > 0 li_byte[i] = Mod(ll_long, 256) i++ ll_long = Truncate(ll_long/256, 0) Loop li_byte[i] = Mod(ll_long, 256) For j = 1 To i a_byte[j] += Byte(String(li_byte[j])) Next Return 1 end function public function blob of_blob (byte a_byte[]);//==================================================================== // Function: nvo_authenticator.of_blob() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value byte a_byte[] //-------------------------------------------------------------------- // Returns: blob //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.of_blob ( byte a_byte[] ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer i Blob lblb lblb = Blob ( Space(UpperBound(a_byte)), EncodingUTF8! ) for i = 1 to UpperBound(a_byte) SetByte(lblb, i, a_byte[i]) Next Return lblb end function private subroutine of_finalcleanup ();//==================================================================== // Function: nvo_authenticator.of_finalcleanup() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.of_finalcleanup ( ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== If il_hAlg > 0 Then BCryptCloseAlgorithmProvider(il_hAlg, 0) End If If il_hRanAlg > 0 Then BCryptCloseAlgorithmProvider(il_hRanAlg, 0) End If If il_hHash > 0 Then BCryptDestroyHash(il_hHash) End If If il_hKey > 0 Then BCryptDestroyKey(il_hKey) End If end subroutine public function unsignedlong of_getlasterror (ref string as_msgtext);//==================================================================== // Function: nvo_authenticator.of_getlasterror() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // reference string as_msgtext //-------------------------------------------------------------------- // Returns: unsignedlong //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.of_getlasterror ( ref string as_msgtext ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Constant ULong FORMAT_MESSAGE_FROM_SYSTEM = 4096 Constant ULong LANG_NEUTRAL = 0 ULong lul_error, lul_Size = 255 lul_error = GetLastError() as_msgtext = Space(lul_Size) FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, lul_error, LANG_NEUTRAL, as_msgtext, lul_Size, 0) Return lul_error end function private subroutine of_errorcleanup (string as_function);//==================================================================== // Function: nvo_authenticator.of_errorcleanup() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_function //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.of_errorcleanup ( string as_function ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== LastFunction = as_function LastErrCode = of_GetLastError(LastErrText) of_FinalCleanup() end subroutine private function boolean nt_success (unsignedlong ntstatus);//==================================================================== // Function: nvo_authenticator.nt_success() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value unsignedlong ntstatus //-------------------------------------------------------------------- // Returns: boolean //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.nt_success ( unsignedlong ntstatus ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== LastErrCode = NTSTATUS If NTSTATUS = 0 Then Return True Else Return False End If end function public function blob of_hmac (string as_algorithm, blob ablb_message, blob ablb_secret);//==================================================================== // Function: nvo_authenticator.of_hmac() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_algorithm // value blob ablb_message // value blob ablb_secret //-------------------------------------------------------------------- // Returns: blob //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.of_hmac ( string as_algorithm, blob ablb_message, blob ablb_secret ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Blob lblb_NullReturn, lblb_pbHashObject, lblb_pbHash Long ll_cbHashObject, ll_cbHash ULong lul_cbData SetNull(lblb_NullReturn) // open an algorithm handle If Not NT_SUCCESS(BCryptOpenAlgorithmProvider(il_hAlg, & as_algorithm, Null, & BCRYPT_ALG_HANDLE_HMAC)) Then of_ErrorCleanup("BCryptOpenAlgorithmProvider") Return lblb_NullReturn End If // calculate the size of the buffer to hold the hash object If Not NT_SUCCESS(BCryptGetProperty(il_hAlg, & BCRYPT_OBJECT_LENGTH, & ll_cbHashObject, 4, lul_cbData, 0)) Then of_ErrorCleanup("BCryptGetProperty BCRYPT_OBJECT_LENGTH") Return lblb_NullReturn End If lblb_pbHashObject = Blob(Space(ll_cbHashObject), iEncoding) // calculate the length of the hash If Not NT_SUCCESS(BCryptGetProperty(il_hAlg, & BCRYPT_HASH_LENGTH, & ll_cbHash, 4, lul_cbData, 0)) Then of_ErrorCleanup("BCryptGetProperty BCRYPT_HASH_LENGTH") Return lblb_NullReturn End If lblb_pbHash = Blob(Space(ll_cbHash), iEncoding) // create a hash If Not NT_SUCCESS(BCryptCreateHash(il_hAlg, & il_hHash, lblb_pbHashObject, & ll_cbHashObject, ablb_secret, Len(ablb_secret), 0)) Then of_ErrorCleanup("BCryptCreateHash") Return lblb_NullReturn End If // hash some data If Not NT_SUCCESS(BCryptHashData(il_hHash, & ablb_Message, Len(ablb_Message), 0)) Then of_ErrorCleanup("BCryptHashData") Return lblb_NullReturn End If // close the hash If Not NT_SUCCESS(BCryptFinishHash(il_hHash, & lblb_pbHash, ll_cbHash, 0)) Then of_ErrorCleanup("BCryptFinishHash") Return lblb_NullReturn End If // final cleanup of_FinalCleanup() Return lblb_pbHash end function public function long get_qrcode_bitmap (string as_filename, string as_text, long al_errcorlvl, long al_bordersize, long al_scale);// The function creates a BITMAP file with a QR code (the version of the QR code is selected automatically from 1 to 40) (Mask Pattern is selected automatically) // Options: // fileName Path and name of the file to be created (C: \ Temp \ qrCode.bmp) (UTF-16 encoding) // text Text to encode (1-4096) (Limited to 4096 characters) (UTF-16 encoding) // errCorLvl Error correction level (0-4). // QR code has a special mechanism to increase the reliability of encrypted information storage. // For codes created with the highest level of reliability, up to 30% of the surface can be damaged or erased, // but they will save information and be read correctly. // Increasing the level helps to increase the reliability of information storage, // but leads to an increase in the size of the matrix code. // 0 - Low (Allowable percentage of violations is about 7%) // 1 - Medium (Allowable percentage of violations is about 15%) // 2 - Quartile (Allowable percentage of violations is about 25%) // 3 - High (Allowable percentage of violations is about 30%) // borderSize Size of the white border around in modules (limited to 0-100) // scale Unit size in pixels (limited to 1-100) // // Returned value: // 0 - Successful execution // 1 - Error fileName, or incorrect path, or error opening file // 2 - Error text, incorrect length of the encoded text // 3 - Error errCorLvl, wrong level of error correction // 4 - Error borderSize, wrong border size // 5 - Error scale, incorrect module size // 6 - Error converting the encoding of the encoded text from UTF-16 to UTF-8 (the buffer for UTF-8 is also 4096 characters and it may not be enough) // 7 - Error receiving QR code return CreateBmpFile(as_fileName, as_text, al_errCorLvl, al_borderSize, al_scale); end function public function long get_qrcode_bitmap (string as_filename, string as_text); //==================================================================== // Function: nvo_authenticator.get_qrcode_bitmap() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_filename // value string as_text //-------------------------------------------------------------------- // Returns: long //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.get_qrcode_bitmap ( string as_filename, string as_text ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Return get_qrcode_bitmap(as_fileName, as_text, 1, 4, 4); end function public function string generatepin (string key, boolean ab_keytypebase32);//==================================================================== // Function: nvo_authenticator.generatepin() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string key // value boolean ab_keytypebase32 //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.generatepin ( string key, boolean ab_keytypebase32 ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long TotalSeconds, CurrentInterval, IntervalLength = 30 TotalSeconds = getunixepoch() CurrentInterval = TotalSeconds/IntervalLength Return generatepin ( Key, CurrentInterval, ab_keytypebase32 ) end function public function string generatepin (string as_key, long counter, boolean ab_keytypebase32);//==================================================================== // Function: nvo_authenticator.generatepin() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_key // value long counter // value boolean ab_keytypebase32 //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.generatepin ( string as_key, long counter, boolean ab_keytypebase32 ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== byte hashBytes[], counterBytes[], offset, selectedByte Blob counterHashBlob, counterBlob, keyBlob String counterHash, pin Integer li_count, i, pinLen Long selectedLong Long selectedMod String ls_key //Convert the counter to byte array and then to blob longtobytearray ( counter, counterBytes ) counterBlob = of_blob ( counterBytes ) If ab_keytypebase32 Then ls_key = GetBase32Decode(as_key) Else ls_key = as_key End If //Convert key to blob and has counter keyBlob = Blob ( ls_key, EncodingUTF8! ) counterHashBlob = of_hmac("SHA1", counterBlob, keyBlob) //Convert result back to byte array Int li_max, li_idx li_max = Len(counterHashBlob) For li_idx = 1 To li_max hashBytes[li_idx] = Byte(BlobMid(counterHashBlob, li_idx, 1)) Next //Get the last byte li_count = UpperBound ( hashBytes ) //And use that to determine the offset into the byte array that we'll start with offset = bitwiseand ( hashBytes[li_count], 15 ) //Calculate the selectedLong value using the selected bytes For i = 1 To 4 selectedByte = hashBytes[offset + i] Choose Case i Case 1 //Strip the most significant bit selectedByte = bitwiseand ( selectedByte, 127 ) selectedLong = selectedLong + selectedByte * 2^24 Case 2 selectedLong = selectedLong + selectedByte * 2^16 Case 3 selectedLong = selectedLong + selectedByte * 2^8 Case 4 selectedLong = selectedLong + selectedByte End Choose Next selectedMod = Mod ( selectedLong, 1000000 ) pin = String ( selectedMod ) pinLen = Len ( pin ) pin = Fill ( '0', 6 - pinLen ) + pin Return pin end function public function string generateprovisioningimage (string identifier, string as_key, boolean ab_keytypebase32);//==================================================================== // Function: nvo_authenticator.generateprovisioningimage() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string identifier // value string as_key // value boolean ab_keytypebase32 //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: nvo_authenticator.generateprovisioningimage ( string identifier, string as_key, boolean ab_keytypebase32 ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Blob lblb_provision_url String ls_keystring, ls_provision_url Long ll_retval String ls_url String ls_qrcode If ab_keytypebase32 Then ls_keystring = as_key Else ls_keystring = GetBase32Encode( as_key) End If ls_provision_url = 'otpauth://totp/' + identifier + '?secret=' + ls_keystring lblb_provision_url = Blob ( ls_provision_url, EncodingUTF8! ) ls_url = String(lblb_provision_url, EncodingUTF8!) ls_qrcode = "qrcodeotp.bmp" ll_retval = get_qrcode_bitmap(ls_qrcode, ls_url, 1, 5, 5) If ll_retval = 0 Then Return ls_qrcode Else Return "" End If Return "" end function on nvo_authenticator.create call super::create TriggerEvent( this, "constructor" ) end on on nvo_authenticator.destroy TriggerEvent( this, "destructor" ) call super::destroy end on |
uo_otp from userobject
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
forward global type uo_otp from userobject end type type p_copy from picture within uo_otp end type type st_time from statictext within uo_otp end type type p_qrcode from picture within uo_otp end type type st_appname from statictext within uo_otp end type type hpb_process from hprogressbar within uo_otp end type type st_account from statictext within uo_otp end type type st_pin from statictext within uo_otp end type type ov_1 from oval within uo_otp end type end forward global type uo_otp from userobject integer width = 1221 integer height = 580 long backcolor = 67108864 string text = "none" long tabtextcolor = 33554432 long picturemaskcolor = 536870912 p_copy p_copy st_time st_time p_qrcode p_qrcode st_appname st_appname hpb_process hpb_process st_account st_account st_pin st_pin ov_1 ov_1 end type global uo_otp uo_otp type variables Private: String is_key = "" String is_appname = "" String is_account = "" Boolean ib_keytypebase32 = false uo_timing iuo_timing end variables forward prototypes public subroutine of_start () public subroutine of_ini (string as_key, string as_appname, string as_account, boolean ab_keytypebase32) end prototypes public subroutine of_start ();//==================================================================== // Function: uo_otp.of_start() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: uo_otp.of_start ( ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Int li_Second If IsNull(is_key) Or Len(Trim(is_key)) = 0 Then Return li_Second = Integer(String(Now(), "ss")) If Mod(li_Second, 30) = 0 Then String ls_pin nvo_authenticator lnv_pin ls_pin = lnv_pin.generatepin( is_key, ib_keytypebase32 ) st_pin.Text = ls_pin End If hpb_process.Position = Mod((60 - li_Second) , 30) st_time.Text = String(Mod((60 - li_Second) , 30)) end subroutine public subroutine of_ini (string as_key, string as_appname, string as_account, boolean ab_keytypebase32);//==================================================================== // Function: uo_otp.of_ini() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_key // value string as_appname // value string as_account // value boolean ab_keytypebase32 //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/05/30 //-------------------------------------------------------------------- // Usage: uo_otp.of_ini ( string as_key, string as_appname, string as_account, boolean ab_keytypebase32 ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== is_key = as_key is_appname = as_appname is_account = as_account ib_keytypebase32 = ab_keytypebase32 st_appname.Text = "App Name: " + is_appname st_account.Text = "Account: " + is_account If Not IsNull(is_account) And Len(Trim(is_account)) > 0 Then nvo_authenticator lnv_pin st_pin.Text = lnv_pin.generatepin( is_key, ib_keytypebase32 ) End If end subroutine on uo_otp.create this.p_copy=create p_copy this.st_time=create st_time this.p_qrcode=create p_qrcode this.st_appname=create st_appname this.hpb_process=create hpb_process this.st_account=create st_account this.st_pin=create st_pin this.ov_1=create ov_1 this.Control[]={this.p_copy,& this.st_time,& this.p_qrcode,& this.st_appname,& this.hpb_process,& this.st_account,& this.st_pin,& this.ov_1} end on on uo_otp.destroy destroy(this.p_copy) destroy(this.st_time) destroy(this.p_qrcode) destroy(this.st_appname) destroy(this.hpb_process) destroy(this.st_account) destroy(this.st_pin) destroy(this.ov_1) end on event constructor;iuo_timing = Create uo_timing iuo_timing.of_ini( This) iuo_timing.Start( 1) end event event destructor;Destroy iuo_timing end event type p_copy from picture within uo_otp integer x = 809 integer y = 336 integer width = 73 integer height = 72 boolean originalsize = true string picturename = "copy.bmp" boolean focusrectangle = false end type event clicked;String ls_pin ls_pin = st_pin.Text Clipboard (ls_pin) MessageBox("infor", "Pin Your Copied: " + ls_pin) end event type st_time from statictext within uo_otp integer x = 1006 integer y = 340 integer width = 137 integer height = 96 integer textsize = -15 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "30" alignment alignment = center! boolean focusrectangle = false end type type p_qrcode from picture within uo_otp integer x = 978 integer y = 20 integer width = 197 integer height = 152 string pointer = "HyperLink!" string picturename = "qrcode.bmp" boolean border = true boolean focusrectangle = false end type event clicked;string ls_qrcode, ls_app nvo_authenticator lnv_pin ls_app = is_appname + ':' + is_account ls_qrcode = lnv_pin.generateprovisioningimage (ls_app, is_key, ib_keytypebase32 ) if FileExists ( ls_qrcode ) then OpenWithParm (w_qrcode, ls_qrcode) end if end event type st_appname from statictext within uo_otp integer x = 32 integer y = 20 integer width = 896 integer height = 124 integer textsize = -15 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "App Name: PMIT" boolean focusrectangle = false end type type hpb_process from hprogressbar within uo_otp integer x = 32 integer y = 468 integer width = 896 integer height = 68 unsignedinteger maxposition = 30 unsignedinteger position = 1 integer setstep = 1 end type type st_account from statictext within uo_otp integer x = 32 integer y = 168 integer width = 896 integer height = 88 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Account: pb.baoga" boolean focusrectangle = false end type type st_pin from statictext within uo_otp integer x = 32 integer y = 276 integer width = 896 integer height = 172 integer textsize = -28 integer weight = 700 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "123456" boolean focusrectangle = false end type event clicked;String ls_pin ls_pin = This.Text Clipboard (ls_pin) MessageBox("infor", "Pin Your Copied: " + ls_pin) end event type ov_1 from oval within uo_otp long linecolor = 33554432 integer linethickness = 4 long fillcolor = 1073741824 integer x = 974 integer y = 304 integer width = 210 integer height = 172 end type |
uo_timing from timing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
forward global type uo_timing from timing end type end forward global type uo_timing from timing end type global uo_timing uo_timing type variables PowerObject ipos end variables forward prototypes public subroutine of_ini (powerobject pos) end prototypes public subroutine of_ini (powerobject pos);ipos = pos end subroutine on uo_timing.create call super::create TriggerEvent( this, "constructor" ) end on on uo_timing.destroy TriggerEvent( this, "destructor" ) call super::destroy end on event timer;If IsValid(ipos) Then ipos.Dynamic Function of_start() End If end event |
w_add from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
forward global type w_add from window end type type cb_delete from commandbutton within w_add end type type dw_data from datawindow within w_add end type type st_3 from statictext within w_add end type type st_2 from statictext within w_add end type type st_1 from statictext within w_add end type type sle_key from singlelineedit within w_add end type type sle_account from singlelineedit within w_add end type type sle_appname from singlelineedit within w_add end type type cbx_base32 from checkbox within w_add end type type cb_update from commandbutton within w_add end type type cb_add from commandbutton within w_add end type end forward global type w_add from window integer width = 2816 integer height = 1644 boolean titlebar = true string title = "Config" boolean controlmenu = true windowtype windowtype = response! long backcolor = 67108864 string icon = "AppIcon!" boolean center = true cb_delete cb_delete dw_data dw_data st_3 st_3 st_2 st_2 st_1 st_1 sle_key sle_key sle_account sle_account sle_appname sle_appname cbx_base32 cbx_base32 cb_update cb_update cb_add cb_add end type global w_add w_add on w_add.create this.cb_delete=create cb_delete this.dw_data=create dw_data this.st_3=create st_3 this.st_2=create st_2 this.st_1=create st_1 this.sle_key=create sle_key this.sle_account=create sle_account this.sle_appname=create sle_appname this.cbx_base32=create cbx_base32 this.cb_update=create cb_update this.cb_add=create cb_add this.Control[]={this.cb_delete,& this.dw_data,& this.st_3,& this.st_2,& this.st_1,& this.sle_key,& this.sle_account,& this.sle_appname,& this.cbx_base32,& this.cb_update,& this.cb_add} end on on w_add.destroy destroy(this.cb_delete) destroy(this.dw_data) destroy(this.st_3) destroy(this.st_2) destroy(this.st_1) destroy(this.sle_key) destroy(this.sle_account) destroy(this.sle_appname) destroy(this.cbx_base32) destroy(this.cb_update) destroy(this.cb_add) end on event open;If FileExists( "data.xml") Then dw_data.ImportFile( "data.xml") End If end event type cb_delete from commandbutton within w_add integer x = 750 integer y = 636 integer width = 283 integer height = 112 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Delete" end type event clicked;If dw_data.GetRow() > 0 Then dw_data.DeleteRow(dw_data.GetRow()) dw_data.SaveAs("data.xml", XML!, False) End If end event type dw_data from datawindow within w_add integer x = 50 integer y = 784 integer width = 2702 integer height = 720 integer taborder = 40 string title = "none" string dataobject = "d_data" boolean hscrollbar = true boolean vscrollbar = true boolean livescroll = true borderstyle borderstyle = stylelowered! end type event rowfocuschanged;String ls_appname, ls_account, ls_key, ls_base ls_appname = This.GetItemString(This.GetRow(), "appname") ls_account = This.GetItemString(This.GetRow(), "account") ls_key = This.GetItemString(This.GetRow(), "key") ls_base = This.GetItemString(This.GetRow(), "base") sle_appname.Text = ls_appname sle_account.Text = ls_account sle_key.Text = ls_key If ls_base = "1" Then cbx_base32.Checked = True Else cbx_base32.Checked = False End If end event event constructor;Long ll_columns,ll_i String ls_colName ll_columns = Long(This.Object.DataWindow.Column.Count) For ll_i = 1 To ll_columns ls_colName = This.Describe( "#" + String( ll_i ) + ".Name" ) This.Modify(ls_colName+".Background.Color='255~t if(Getrow() = currentRow(),11665407,if(mod(getrow(),2 ) =0,rgb(231, 255, 231),rgb(255,255,255)))'") Next end event type st_3 from statictext within w_add integer x = 73 integer y = 396 integer width = 347 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Key:" alignment alignment = right! boolean focusrectangle = false end type type st_2 from statictext within w_add integer x = 73 integer y = 244 integer width = 347 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Account:" alignment alignment = right! boolean focusrectangle = false end type type st_1 from statictext within w_add integer x = 73 integer y = 88 integer width = 347 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "App Name:" alignment alignment = right! boolean focusrectangle = false end type type sle_key from singlelineedit within w_add integer x = 443 integer y = 360 integer width = 2149 integer height = 112 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type sle_account from singlelineedit within w_add integer x = 443 integer y = 216 integer width = 2149 integer height = 112 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type sle_appname from singlelineedit within w_add integer x = 443 integer y = 68 integer width = 2149 integer height = 112 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type cbx_base32 from checkbox within w_add integer x = 453 integer y = 516 integer width = 690 integer height = 80 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Key Base32 Encode" end type type cb_update from commandbutton within w_add integer x = 434 integer y = 636 integer width = 283 integer height = 112 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Update" end type event clicked;String ls_appname, ls_account, ls_key, ls_base ls_appname = sle_appname.Text ls_account = sle_account.Text ls_key = sle_key.Text If cbx_base32.Checked Then ls_base = "1" Else ls_base = "0" End If dw_data.SetItem(dw_data.GetRow(), "appname",ls_appname ) dw_data.SetItem(dw_data.GetRow(), "account", ls_account) dw_data.SetItem(dw_data.GetRow(), "key", ls_key) dw_data.SetItem(dw_data.GetRow(), "base", ls_base) dw_data.SaveAs("data.xml", XML!, false) end event type cb_add from commandbutton within w_add integer x = 123 integer y = 632 integer width = 283 integer height = 112 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Add" end type event clicked;String ls_appname, ls_account, ls_key, ls_base ls_appname = sle_appname.Text ls_account = sle_account.Text ls_key = sle_key.Text If cbx_base32.Checked Then ls_base = "1" Else ls_base = "0" End If dw_data.ScrollToRow( dw_data.InsertRow(0) ) dw_data.SetItem(dw_data.GetRow(), "appname",ls_appname ) dw_data.SetItem(dw_data.GetRow(), "account", ls_account) dw_data.SetItem(dw_data.GetRow(), "key", ls_key) dw_data.SetItem(dw_data.GetRow(), "base", ls_base) dw_data.SaveAs("data.xml", XML!, false) end event |
w_qrcode from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
forward global type w_qrcode from window end type type p_qrcode from picture within w_qrcode end type end forward global type w_qrcode from window integer width = 974 integer height = 948 boolean titlebar = true string title = "QRCode" boolean controlmenu = true windowtype windowtype = response! long backcolor = 67108864 string icon = "AppIcon!" boolean center = true p_qrcode p_qrcode end type global w_qrcode w_qrcode on w_qrcode.create this.p_qrcode=create p_qrcode this.Control[]={this.p_qrcode} end on on w_qrcode.destroy destroy(this.p_qrcode) end on event open;String ls_StringParm ls_StringParm = Message.StringParm If Not IsNull(ls_StringParm) And Len(Trim(ls_StringParm)) > 0 Then p_qrcode.PictureName = ls_StringParm End If end event type p_qrcode from picture within w_qrcode integer x = 9 integer width = 946 integer height = 856 boolean originalsize = true boolean focusrectangle = false end type |
w_main from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
forward global type w_main from window end type type p_add from picture within w_main end type end forward global type w_main from window integer width = 2633 integer height = 2372 boolean titlebar = true string title = "OTP Two Factor Authentication ( 2FA )" boolean controlmenu = true boolean minbox = true boolean maxbox = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true p_add p_add end type global w_main w_main type variables uo_otp iuo_otp[] uo_otp iuo_otpnull[] end variables forward prototypes public subroutine of_loadotp () end prototypes public subroutine of_loadotp ();//remove objects Int li_r For li_r = 1 To UpperBound (iuo_otp) If IsValid( iuo_otp[li_r] ) Then This.CloseUserObject ( iuo_otp[li_r] ) End If Next //reset iuo_otp[] = iuo_otpnull[] // add otp If FileExists("data.xml" ) Then datastore lds lds = Create datastore lds.DataObject = "d_data" lds.ImportFile( "data.xml") If lds.RowCount() > 0 Then Int li_row, li_optrow, li_optcolumn Long lx, ly li_optrow = -1 For li_row = 1 To lds.RowCount() iuo_otp[li_row] = Create uo_otp String ls_appname, ls_account, ls_key, ls_base Boolean lb_keytypebase32 ls_appname = lds.GetItemString(li_row, "appname") ls_account = lds.GetItemString(li_row, "account") ls_key = lds.GetItemString(li_row, "key") ls_base = lds.GetItemString(li_row, "base") If ls_base = "1" Then lb_keytypebase32 = True Else lb_keytypebase32 = False End If iuo_otp[li_row].of_ini (ls_key, ls_appname,ls_account, lb_keytypebase32) iuo_otp[li_row].Border = True If Mod(li_row,2) = 0 Then li_optcolumn = 1 Else li_optcolumn = 0 li_optrow += 1 End If lx = li_optcolumn * iuo_otp[li_row].Width + ((li_optcolumn + 1 )* 50) ly = li_optrow * ( iuo_otp[li_row].Height + 50) + 50 This.OpenUserObject(iuo_otp[li_row], lx, ly) Next End If End If end subroutine on w_main.create this.p_add=create p_add this.Control[]={this.p_add} end on on w_main.destroy destroy(this.p_add) end on event resize;p_add.x = this.width - p_add.width - 60 p_add.y = this.height - p_add.height - 140 end event event open;of_loadotp() end event type p_add from picture within w_main integer x = 2341 integer y = 2076 integer width = 229 integer height = 180 string pointer = "HyperLink!" string picturename = "add.bmp" boolean border = true borderstyle borderstyle = styleraised! boolean map3dcolors = true end type event clicked;Open(w_add) of_loadotp( ) end event |
Find Projects On Github click here
Good Luck!
Subscribe
Login
0 Comments
Oldest