Page 2 of 2

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 7:02 am
by Fangbeast
I've played that version many a time. :lol:
I play the 3 eyed fondoogolie myself (grin)
And yes; the PostMessage() function has the exact parameter structure as the SendMessage() function; although I don't expect it to be any better.


Well, you are talking to the API blonde here (heheheheh) so it isn't as if I'd know:):)

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 7:49 am
by TI-994A
Fangbeast wrote:...you are talking to the API blonde here...
Aren't we all. :wink:

Basically, the two functions are alike:

Code: Select all

SendMessage_(GadgetID(0), #EM_SETPASSWORDCHAR, 0, 0)
PostMessage_(GadgetID(0), #EM_SETPASSWORDCHAR, 0, 0)

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 8:55 am
by Dude
TI-994A wrote:the PostMessage() function has the exact parameter structure as the SendMessage() function; although I don't expect it to be any better.
SendMessage and PostMessage send their messages differently, as I said and quoted from MSDN. SendMessage can have a delay, whereas PostMessage doesn't. I've had to use one or the other depending on my need for speed in my own apps.

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 10:45 am
by TI-994A
Dude wrote:SendMessage and PostMessage send their messages differently, as I said and quoted from MSDN. SendMessage can have a delay, whereas PostMessage doesn't.
Yes; but in returning, not in processing.

SendMessage() function:
- messages are issued directly to the window's procedure (WndProc or callback)
- synchronous blocking function, waits for messages to be processed before returning

PostMessage() function:
- messages are simply appended to the primary message queue
- asynchronous non-blocking function, does not wait for messages to be processed, returns immediately

Technically, the SendMessage() function should be faster for processing such API level edit control messages.

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 11:08 am
by Dude
All true, and it depends what the goal is. I wish Fangbeast would try with PostMessage and report if it made a difference (hint, hint). ;)

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 11:19 am
by Fangbeast
Dude wrote:All true, and it depends what the goal is. I wish Fangbeast would try with PostMessage and report if it made a difference (hint, hint). ;)
yes sir!!
Immediately!
If not sooner!!

May I fix some bugs first? (Plaintive whining mode)

***UPDATE***

This is the PostMessage method to show and/or hide the password field. Whether or not I use PostMessage_ or SendMessage_, something is very, very wrong here as it took 51 seconds (Yes, that is not a typo, I tried it twice!!!) to change the password text to unhidden.

Show the password:

Code: Select all

PostMessage_(GadgetID(#Gadget_EditPassword_NewPassWord),     #EM_SETPASSWORDCHAR, 0, 0)
Hide the password:

Code: Select all

PostMessage_(GadgetID(#Gadget_EditPassword_NewPassWord),     #EM_SETPASSWORDCHAR, 42, 0)
Did I type something wrong or miss something in the arguments here because I was only following the code in prior posts exactly.

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 12:13 pm
by Dude
Fangbeast wrote:Whether or not I use PostMessage_ or SendMessage_, something is very, very wrong here as it took 51 seconds (Yes, that is not a typo, I tried it twice!!!) to change the password text to unhidden.
Must be something wrong with your main loop, then. It should be pretty much instant. For such a delay to occur, would indicate lots of main event processing holding things up.

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 3:48 pm
by Mijikai
I also want to share my RandomPassword function :)

It ensures that the password has at least one lower,upper and special character.
Supported length 4 - 128.

Code:

Code: Select all


EnableExplicit

;Compact RandomPassword by Mijikai
;Password length 4 - 128
;PB v.5.62

Procedure.s RandomPassword(Length.i)
  Protected Dim block.a(127)
  Protected index.i
  Protected password.s
  Protected *key.Ascii
  If Length > 3 And Length < 129
    block(0) = Random(25,0)
    block(1) = Random(51,26)
    block(2) = Random(81,52)
    For index = 3 To Length - 1
      block(index) = Random(81,0)
    Next
    RandomizeArray(block(),0,Length - 1)
    For index = 0 To Length - 1
      *key = ?randompassword + block(index) 
      password + Chr(*key\a)
    Next
    ProcedureReturn password
  Else
    ProcedureReturn #Null$;<- DONT USE WITH PB v.5.70!
  EndIf
  randompassword:
  !db 'abcdefghijklmnopqrstuvwxyz'
  !db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  !db 0x21,0x22,0x23,0x24,0x25,0x26
  !db 0x27,0x28,0x29,0x2A,0x2B,0x2C
  !db 0x2D,0x2E,0x2F,0x3A,0x3B,0x3C
  !db 0x3D,0x3E,0x3F,0x40,0x5B,0x5D
  !db 0x5E,0x5F,0x7B,0x7C,0x7D,0x7E
EndProcedure

Debug RandomPassword(64)

End

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 4:27 pm
by AZJIO

Code: Select all

EnableExplicit
Global Error_Procedure = 0
Global xeh$, baza$

Procedure StrToArrLetter(Array Arr.s{1}(1), String$)
	Protected LenStr, i
	LenStr = Len(String$)
	If LenStr
		ReDim Arr(LenStr - 1)
		PokeS(Arr(), String$, -1, #PB_String_NoZero)
	EndIf
EndProcedure

Procedure.s DecToNum(Dec.q, Symbol$)
	Protected Out.s, ost, ArrSz
	Protected Dim Arr.s{1}(1)
	StrToArrLetter(Arr(), Symbol$)
	ArrSz = ArraySize(Arr()) - 1
	If Error_Procedure Or ArrSz < 2
		Error_Procedure = 1
		ProcedureReturn ""
	EndIf
	Repeat
		ost = Mod(Dec, ArrSz)
		Dec = (Dec - ost) / ArrSz
		Out = Arr(ost + 1) + Out
	Until Dec < 1
	ProcedureReturn Out
EndProcedure

UseMD5Fingerprint()
xeh$ = StringFingerprint("purebasic.fr  Fangbeast", #PB_Cipher_MD5)
baza$ =  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
;baza$ =  "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789"
Debug xeh$
xeh$ = Left(xeh$, 15)
Debug xeh$
Debug DecToNum(Val("$" + xeh$), baza$)

Re: Random password generation for apps?

Posted: Wed Feb 27, 2019 5:39 pm
by StarBootics
Hello everyone,

My take on a random password generator :

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; AUTOMATICALLY GENERATED CODE, DO NOT MODIFY
; UNLESS YOU REALLY, REALLY, REALLY MEAN IT !!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Code generated by : Dev-Module - V0.9.10
; Project name : PasswordGenerator
; File name : PasswordGenerator - Module.pb
; File Version : 1.0.0
; Programmation : Demonstrator code
; Programmed by : StarBootics
; Creation Date : 27-02-2019
; Last update : 27-02-2019
; Coded for PureBasic : V5.70 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule PasswordGenerator

  Declare.b GetCurrentSize()
  Declare.b GetWithNonAlphaNumeric()
  Declare SetCurrentSize(P_CurrentSize.b)
  Declare SetWithNonAlphaNumeric(P_WithNonAlphaNumeric.b)
  Declare Initialize()
  Declare Reset()
  Declare.s RunIt()
  
EndDeclareModule

Module PasswordGenerator

  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< Structure declaration <<<<<

  Structure Instance

    CurrentSize.b
    WithNonAlphaNumeric.b

  EndStructure

  Global Instance.Instance

  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The observators <<<<<

  Procedure.b GetCurrentSize()

    ProcedureReturn Instance\CurrentSize
  EndProcedure

  Procedure.b GetWithNonAlphaNumeric()

    ProcedureReturn Instance\WithNonAlphaNumeric
  EndProcedure

  ; <<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The mutators <<<<<

  Procedure SetCurrentSize(P_CurrentSize.b)

    Instance\CurrentSize = P_CurrentSize

  EndProcedure

  Procedure SetWithNonAlphaNumeric(P_WithNonAlphaNumeric.b)

    Instance\WithNonAlphaNumeric = P_WithNonAlphaNumeric

  EndProcedure

  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Initialize operator <<<<<

  Procedure Initialize()
    
    Instance\CurrentSize = 0
    Instance\WithNonAlphaNumeric = 0
    
  EndProcedure

  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The Reset operator <<<<<

  Procedure Reset()
    
    Instance\CurrentSize = 0
    Instance\WithNonAlphaNumeric = 0
    
  EndProcedure
  
  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; <<<<< The RunIt operator <<<<<
  
  Procedure.s RunIt()
    
    Select Instance\WithNonAlphaNumeric
        
      Case #False
        Mode.b = 2
        
      Case #True
        Mode = 8
        
      Default
        Mode = 2
        
    EndSelect 
    
    For Index = 1 To Instance\CurrentSize
      
      Select Random(Mode)
          
        Case 0
          Min_ASCII.w = 48 ; Nombre de 0 à 9
          Max_ASCII.w = 57
          
        Case 1
          Min_ASCII = 97 ; Alphabet Minuscule
          Max_ASCII = 122
          
        Case 2
          Min_ASCII = 65 ; Alphabet Majuscule 
          Max_ASCII = 90
          
        Case 3
          Min_ASCII = 33 ; Ponctuation et symbole
          Max_ASCII = 38
          
        Case 4
          Min_ASCII = 63 ; Symbole --> ? @
          Max_ASCII = 64
          
        Case 5
          Min_ASCII = 91 ; Symbole --> [ \ ]
          Max_ASCII = 93
          
        Case 6
          Min_ASCII = 123 ; Symbole --> { | } ~
          Max_ASCII = 126
          
        Case 7
          Min_ASCII = 162 ; Symbole --> ¢ £ ¤
          Max_ASCII = 164
          
        Case 8
          Min_ASCII = 177 ; Symbole --> ± ² ³
          Max_ASCII = 179
          
      EndSelect
      
      Generated_Password.s = Generated_Password + Chr(Random(Max_ASCII, Min_ASCII))
      
    Next
    
    ProcedureReturn Generated_Password
  EndProcedure
  
EndModule

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code generated in : 00.001 seconds (125000.00 lines/second) <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

CompilerIf #PB_Compiler_IsMainFile
  
  PasswordGenerator::SetCurrentSize(12)
  PasswordGenerator::SetWithNonAlphaNumeric(#False)
  
  For Index = 0 To 10
    Debug PasswordGenerator::RunIt()
  Next
  
  Debug ""
  
  PasswordGenerator::SetWithNonAlphaNumeric(#True)
  
  For Index = 0 To 10
    Debug PasswordGenerator::RunIt()
  Next

CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Best regards
Starbootics

Re: Random password generation for apps?

Posted: Thu Feb 28, 2019 5:02 am
by Fangbeast
This is what I love about the forums. A lot of good coders give great examples and then it is up to me to put it all together. I settled on a solution shown in this thread for the password generation and now a few more things need to be done.

MyInfo is suffering from feature creep as I need something to do. LOL!!

1. Redo the program wide font change capability. Not working properly last time. (Requested)
2. Let users change their own colours. (Requested)
3. Implement an auto locking mechanism. Will need help with that.
4. Add an update checking mechanism.

All of the techniques in MyInfo will make it into all my programs so that people can take any of them and rip their guts out for themselves.

Thanks folks!!

Re: Random password generation for apps?

Posted: Thu Feb 28, 2019 7:13 am
by Mijikai
I updated my Password Generator now it is safe to use for cryptographic purposes.
It does not use the predictable Random() function anymore.
The password contains at least a number, upper-, lowercase and special char.
Supported length as before 4 - 128.

Link:
https://www.purebasic.fr/german/viewtop ... =8&t=31320

Re: Random password generation for apps?

Posted: Thu Feb 28, 2019 9:26 am
by Fangbeast
All contributions only make it better for everyone.