Using InputBox to get password in VB

I am using an inputbox (NOT A TEXT BOX) to request a password. Is there a way to replace the typed characters with a different character (such as “*”) to hide the real password?

Thank you.

Not natively in an inputbox, although I’m guessing it might* be possible with some fancy API work.

Is there a reason you are using an inputbox?

Well, I tried that…

I couldn’t find any APIs that could be used for interrupting KeyPresses to an InputBox…

Check and their message boards. Good place…never had a problem that couldn’t be answered

I think this is what you’re looking for:

I tried it in VB6, and it seemed to work just fine.


I still don’t understand the reasoning behind an inputbox, considering how much more flexibility you get with a textbox.

SoulFrost’s example looked like it would do the trick, but considering the amount of declares required, the loss of readability, and no guarantee of future compatibility for APIs, I’m not sure of a circumstance where it would be the preferred method.

Would you care to share?

It was the example used in class. Basically the program was only to be able to be exited if the user had the correct password. So the InputBox was used. I didn’t think it was any good that the password chars were visable and my teacher didn’t know off the top of his head how to mask them.

You can only EXIT a program with the correct password?

How strange…

If you wanted to be really mean, you could’ve used a textbox on a modal form.


…well it was “intended” to be run in a store where it was the only thing running at the computer. so by only being able to exit by knowing the password, it would prevent people from getting anywhere else on the computer.

Wouldn’t you also need to remove the program’s listing from the Close Program box (Control+Alt+Delete)?

That’s pretty easily done, too.


Do you mean this?

<input type=password name=password>

that’ll render ***s for you and the value will be equal to the actual text typed.

Well I didn’t look over the link too much, but I would do something like this. Please note it’s been a long time so I’m going from memory. You can also try looking in VB in 21 days as that’s where I learned quite a lot.

You said the Keypress isn’t there for the input box? Well then set the whole program for keypress. (I think that’s what you’re looking for) Then when a key is pressed the first thing you would do is put the letter into a password string, then change the letter to a * so it can be shown. Then take the next letter and “add” it to the password and repeat. You’d have to subtract the letter if a backspace was used. I’d guess it look something like this.

KeyPress.down (whatever goes in here about keypress)

if keypress(x)<> “" then

else if keypress(x)=BACKSPACE then
password=(I know there is something to remove just one letter but I don’t remember it."
end if

I know there is more to it than that, but that’s the way I would go about it. If the input box doesn’t alow the KeyPress then making the whole program will allow you to catch everything typed in while the program is running. IANAP though so take it for what it’s worth which is probably less than .02 cents.


It sounds like you’re going to make a pretty damn good programmer, based on the way you think these things through. Now, tell your teacher to stop teaching inputbox use.

I used to use them for quick and dirty projects that were intended to be used for a few days and then deleted, as they are slightly quicker to program than a textbox on a form. Then I learned that, in corporate environments, the lifespan of quick and dirty program use averaged about 10 years. :slight_smile: