Subject Re: PasswordMaskEF.cc bug?
From Bernd Hohenester <newsletter@hobe.de>
Date Sun, 25 Feb 2024 11:58:52 -0500
Newsgroups dbase.getting-started
Attachment(s) password.jpg

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

         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, 1))
                   msgbox( "Password contains invalid chars!", "ALERT!", 48)
                   this.value := ""
                   this.setFocus()
                   this.enteredPasswort = ""
                 endif
               endfor


>          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 many thanks for your idea with the "reveal" button. I have to work on it, but the optic is well (see password.jpg".

cu
Bernd