AllExperts > Qbasic, Quickbasic 
Search      
Qbasic, Quickbasic
Volunteer
Answers to thousands of questions
 Home · More Qbasic, Quickbasic Questions · Answer Library  · Encyclopedia ·
More Qbasic, Quickbasic Answers
Question Library

Ask a question about Qbasic, Quickbasic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Alex Barry
Expertise
I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, c/c++, python, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.

Experience
Hobby programming since 2000

I no longer belong to any community programming groups, but do have knowledge of *basic dialects and C/C++

 
   

You are here:  Experts > Computing/Technology > Basic > Qbasic, Quickbasic > hide password details

Qbasic, Quickbasic - hide password details


Expert: Alex Barry - 7/12/2009

Question
hi.how do i hide password details so when i input my password it displays *'s

Answer
Hi, Rasheed,

I've heard a lot of people ask this question (here, and on various qbasic forums), so I can definately help you out with it.

Here is a function I'd use:

' The declaration of the function
' Here is how you'd call it:
' DIM password AS STRING
' password = PasswordInput( "Password: ", "*" )
DECLARE FUNCTION PasswordInput( prompt AS STRING, passwordChar AS STRING ) AS STRING

FUNCTION PasswordInput( prompt AS STRING, passwordChar AS STRING ) AS STRING
DIM pchar AS STRING * 1
DIM key AS STRING * 1
DIM passStr AS STRING
' Set the password char to make sure it's only 1 character long (you could change this...)
pchar = passwordChar
' Make sure the password is reset
passStr = ""
PRINT prompt;
DO
  key = INKEY$
  ' Make sure we got a key from the input
  IF LEN( RTRIM$( key ) ) > 0 THEN
    SELECT CASE ASC( key )
    CASE 8
      ' Backspace
      ' Make sure there are characters to delete
      IF LEN( passStr ) > 1 THEN
        PRINT CHR$(8); " "; CHR$( 8 );
        passStr = LEFT$( passStr, LEN( passStr ) - 1 )
      END IF
    CASE 13
      ' Enter/Return key
      EXIT DO
    CASE ELSE
      ' Any other key (ASCII 32 - [255])
      IF ( ASC( key ) >= 32 ) THEN
        passStr = passStr + key
        PRINT pchar;
    END SELECT
    key$ = ASC( 0 )
  END IF
LOOP
FUNCTION = passStr
END FUNCTION

If you have any problems with the code, let me know, as I am doing that from memory.

Take care,
-Alex

EDIT:
I had to make the INKEY$ function aware when no key is pressed

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.