AboutAlex 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++
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