Using INTDOSQQ for Password Entry in FORTRAN 5.1

Last reviewed: July 19, 1995
Article ID: Q93905
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, version 5.1

SUMMARY

You can create a program that allows for password entry using Microsoft FORTRAN version 5.1 for MS-DOS. The Microsoft FORTRAN "Reference" manual for version 5.1 explains using the INTDOSQQ and INTDOSXQQ subroutines to invoke MS-DOS system calls using Interrupt 21h. Interrupt 21h Functions 7 and 8 retrieve input from the keyboard without echoing the input to the display. Interrupt 21h Function 7 ignores the CTRL+C and CTRL+BREAK key combinations while Interrupt 21h Function 8 processes these key combinations by terminating the program. For more information about the various functions provided by Interrupt 21h, see the "MS-DOS Encyclopedia" or another reference on programming in the MS-DOS environment.

MORE INFORMATION

The following sample code use MS-DOS Interrupt 21h Function 7 to allow the user to enter a password without echoing the keystrokes to the display. The application uses Interrupt 21h Function 2 to display an asterisk on the screen for each keystroke entered.

Sample Code

C Compiler options required: None

      include 'flib.fi'
      program password
      character*80 pass
      logical get_pass/.true./
      integer*2 i, j, getch

      write(*,'(1x,a,\)') 'ENTER PASSWORD > '
      i=1
      do while (get_pass)
         j = getch()            ! Get a character of the password
         if (j .le. 32) then
            if (j .eq. 8 .and. i .gt. 1) then   ! BACKSPACE key pressed
               i = i-1
               call putchar( char(j) )    ! Move cursor back 1 character
               call putchar( ' ' )        ! Write a blank over the asterisk
               call putchar ( char(j) )   ! Move cursor back to blanks
               pass(i:i+1) = '  '
            endif
            if (j .eq. 13) get_pass = .false. ! ENTER key pressed - exit
         else
            call putchar( '*' )           ! Echo asterisk to display
            pass(i:i) = char(j)           ! Add input character to string
            i = i + 1
            if (i .gt. 80) get_pass = .false. ! Don't write past string end
         endif
      enddo
      write(*,*)
      write(*,*) 'password entered > ',pass
      end

C The GETCH function retrieves a character from the C Standard Input without echoing the character to the screen.

      integer*2 function getch
      include 'flib.fd'
      record /regs$info/ in, out
      in.bregs.ah = #07            ! Function 7 - STDIN Input (no echo)
      call intdosqq(in, out)       ! Interrupt 21h
      getch = out.bregs.al         ! Input data returned in AL
      return
      end

C The PUTCHAR subroutine writes a single character to the screen.

      subroutine putchar( ch )
      include 'flib.fd'
      record /regs$info/ in, out
      character*1 ch
      in.bregs.ah = #02            ! Function 2 - Display Output
      in.bregs.dl = ch             ! character to display goes in DL
      call intdosqq(in, out)       ! Interrupt 21h
      return
      end


Additional reference words: kbinf 5.10
KBCategory: kbprg kbcode
KBSubcategory: FORTLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 19, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.