How can I let a user enter a password and hide the characters entered?

How can I let a user enter a password and hide the characters entered?

How can I let a user enter a password and hide the charactersentered?

You can let the user enter characters into a field and replace theletters entered by using the OnKey() method of the object. TheOnKey() method is triggered whenever the user enters a keystroke intothe field. The OnKey() method gives you three parameters: thekeychar, the keycode, and the shift parameter. The keychar gives youthe character that was entered, the keycode tells you what type ofkeystroke was entered, and the shift tells you whether the shiftand/or control keys were also pressed. You will only care about thefirst two parameters.

If the keycode parameter is “KEYCODE_CHAR”, which is an internalPower Objects constant which is equal to 0, you know that analphanumeric character or punctuation mark was entered. The codebelow tests to see if the keycode is KEYCODE_CHAR. If it is, it addsthe value of the keychar variable to a user-defined variable calledudpPassword. The code then creates a string which consists of astring of “*” characters which is as long as the current value of theudpPassword property and sets the value of the field to the string.Finally, you return True from the OnKey() method to suppress thenormal processing for the keystroke.

You will also want to test to see if the user has entered theeither arrow keys to navigate through the value entered in the fieldor the DELETE keystroke. Since you are saving the keystrokes enteredin the udpPassword sequentially, your code would be significantlymore complicated if you let your users navigate around in thecharacters, since you would have to determine where the user was inthe string of asterisks and add or delete the keystroke at thecorrect position in the user-defined property. Also, when you usethe code described above to replace characters with an asterisk, theedit cursor for the field is always at the beginning of the field.To avoid complex code, you can just add the code that tells the userthat they can’t use arrow keys or delete keys in entering a passwordand then clear the object to avoid confusion.

      DIM nPointer As Integer      DIM nCounter As Integer      DIM sPassword As String      IF KEYCODE = KEYCODE_CHAR THEN              udpPassword = udpPassword & keychar              nPointer = 1              nLength = Len(udpPassword)              DO UNTIL nPointer > nLength                      sPassword = sPassword & "*                      nPointer = nPointer + 1              LOOP              Self.Value = sPassword              OnKey = True      ELSEIF KEYCODE = KEYCODE_BACKSPACE OR keycode = KEYCODE_LEFT &              OR KEYCODE = KEYCODE_RIGHT THEN      MSGBOX ("You must enter your password directly without " & &               "deletions or using the arrow keys.",               16,               "Password Entry")                      OnKey = true                              Self.Value = ""                              udpPassword = ""      END IF        

You will have the same problem if a user leaves the password fieldand then re-enters the field. Let’s just stop this foolishness inits tracks by clearing out the udpPassword property and the value ofthe object itself whenever a user enters the object. To achievethis, add the following code to the FocusEntering() method for theobject.

      Self.Value = ""      udpPassword = ""        

Since passwords are normally only a few characters, this doesn’tseem like such a big imposition on the user, especially to maintainthe integrity of your security system.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as