Subject |
Re: PasswordMaskEF.cc bug? |
From |
Bernd Hohenester <newsletter@hobe.de> |
Date |
Mon, 26 Feb 2024 13:56:49 -0500 |
Newsgroups |
dbase.getting-started |
Bernd Hohenester Wrote:
> Peter Hegelbach Wrote:
>
> > Where I got stuck: Support for Ctrl-C, pasting the password from the
> > clipboard.
>
> i added support for inserting a password. You need to add the following lines:
>
> At the beginning where the "defines" are:
> #define CTRLV_KEY 22 // -- ASCII value of Ctrl+V
>
> And in the function key:
>
> > *-------------------------------------------------------------------------------
> > procedure Key(nChar, nPosition)
> > // Handles keys entered in the password entryfield
> > private enteredChar, returnValue
> >
> > // Get the character positions of the selected text (if any)
> > local SelectStartPos, SelectEndPos
> > SelectStartPos = 0
> > SelectEndPos = 0
> > CheckSelect(this.hwnd,0xB0,SelectStartPos,SelectEndPos)
> > enteredChar = chr(nChar)
> > returnValue = true // By default output whatever key was typed
> > do case // Check for keys that modify the value
> > case nChar = BACKSPACE_KEY
> > // if the text is not selected, delete the previous character,
> > // if the text is selected, delete the characters corresponding
> > // to the selection range
> > if SelectStartPos == 0 AND SelectEndPos == 0
> > this.enteredPassword = ;
> > stuff(this.enteredPassword, nPosition - 1, 1, \"\")
> > else
> > this.enteredPassword = ;
> > stuff(this.enteredPassword, SelectStartPos + 1, ;
> > SelectEndPos - SelectStartPos, \"\")
> > endif
> > case nChar = DELETE_KEY
> > // if the text is not selected, delete the current character,
> > // if the text is selected, delete the characters corresponding
> > // to the selection range
> > if SelectStartPos == 0 AND SelectEndPos == 0
> > this.enteredPassword = ;
> > stuff(this.enteredPassword, nPosition, 1, \"\")
> > else
> > this.enteredPassword = ;
> > stuff(this.enteredPassword, SelectStartPos + 1, ;
> > SelectEndPos - SelectStartPos, \"\")
> > endif
> > case nChar = ENTER_KEY
> > if this.captureEnter AND this.enteredPassword.length = 0
> > msgbox( \"Kein Passwort eingegeben!\",\"Warnung!\", 48 )
> > this.setFocus()
> > endif
// new code! The old was only half of the code ;-)
case nChar = CTRLV_KEY
// password was inserted with Strg+V
// all chars must be validated
for i = 1 to this.value.length
if not class::IsValidChar(this.value.substring(i-1, i))
msgbox( "Passwort contains invalid chars!", "ALERT!", 48)
this.value := ""
this.setFocus()
this.enteredPasswort = ""
return true
endif
endfor
// if we are here, all is well
this.enteredPassword = this.value
this.value := replicate(this.maskChar, this.enteredPassword.length)
>
> > otherwise
> > if class::IsValidChar(enteredChar) // Check if alphanumeric
> > // if the text is not selected, insert the character entered,
> > // if the text is selected, overwrite the characters
> > // corresponding to the selection range with the character
> > // entered
> > if SelectStartPos == 0 AND SelectEndPos == 0
> > this.enteredPassword = ;
> > stuff(this.enteredPassword, nPosition, 1, enteredChar)
> > else
> > this.enteredPassword = ;
> > stuff(this.enteredPassword, SelectStartPos + 1, ;
> > SelectEndPos - SelectStartPos, enteredChar)
> > endif
> > if this.camouflageOn
> > returnValue = asc( this.maskChar ) // Output camouflage character
> > else
> > returnValue = nChar
> > endif
> > else
> > returnValue = false
> > ? chr(7) // Beep
> > endif
> > endcase
> > return returnValue
AND: we have a problem at this point! With "entryfield.key" one has no acces to "this.value". We have to use "entryfield.onKey" and all is well. So you have to rename the function to "function onKey(nChar, nPosition, bShift, bCtrl)" and change the pointer in the beginning "key := class::key" in "onkey := class::onkey".
Bernd
|
|