[an error occurred while processing this directive]

HP OpenVMS Systems

Ask the Wizard
» 

HP OpenVMS Systems

OpenVMS information

» What's new on our site
» Upcoming events
» Configuration and buying assistance
» Send us your comments

HP OpenVMS systems

» OpenVMS software
» Supported Servers
» OpenVMS virtualization
» OpenVMS solutions and partners
» OpenVMS success stories
» OpenVMS service and support
» OpenVMS resources and information
» OpenVMS documentation
» Education and training

Quick Links

» Non-javascript page
» Ask the Wizard
» OpenVMS FAQ

Test Drive OpenVMS

» OpenVMS I64 test drive
» Java test drive

Other information resources available to you include:

» OpenVMS freeware
» ECO kits, software and hardware support, prior version support
» Alpha SRM, ARC, and AlphaBIOS firmware updates
» ENCOMPASS - HP user group
» OpenVMS software downloads, OpenVMS freeware CD-ROM
» OpenVMS firmware locations
» DECconnect passive adaptor charts
» Cables reference guide
» MicroVAX console commands
» OpenVMS student research

Select a topic below to see Questions Frequently Asked by partners

» Using the online documentation library(installing BNU from the asap SDK)
» Global sections(how to create and use.)
» xx$CREATE_BUFOBJ system service(usage)
» Ethernet address(methods of determination)
» Shareable images(cookbook approach to creating one)
» Sharing data/code at absolute addresses(a guide with examples)
» Determining the Alpha microprocessor
» Using GETSYI to get hardware status

Evolving business value

» Business Systems Evolution
» AlphaServer systems transition planning
» Alpha RetainTrust program

Related links

» HP Integrity servers
» HP Alpha systems
» HP storage
» HP software
» HP products and services
» HP solutions
» HP support
disaster proof
HP Integrity server animation
HP Integrity server animation
Content starts here

Ask the Wizard Questions

Programing example for password hash

The Question is:

Can you send me some sample FORTRAN code using SYS$GetUAI
and SYS$Hash_Password which gets the current user's VMS
password in "hash form" and takes a string entered by the
user and converts it to "hash form" and then compares the
two together?

Thanx.


The Answer is:

	PROGRAM UAI_EXAMPLE

C+
C
C ABSTRACT:
C
C     Example showing use of $GETUAI and $HASH_PASSWORD
C
C FUNCTIONAL DESCRIPTION:
C
C     This example demonstrates the use of the $GETUAI and $HASH_PASSWORD
C     OpenVMS System Services.  It prompts the user for the current password
C     and compares it to that user's hashed password as stored in the
C     system SYSUAF.DAT file.  Other routines used are LIB$GETJPI and
C     SMG$READ_STRING
C
C AUTHOR(S):
C
C     Steve Lionel, Digital Equipment Corporation
C
C CREATION DATE:
C
C     31-Jan-1996
C
C-
	IMPLICIT NONE

	INCLUDE '($SYSSRVNAM)'	    ! System service names
	INCLUDE '($JPIDEF)'	    ! $GETJPI definitions
	INCLUDE '($UAIDEF)'	    ! $GETUAI definitions
	INCLUDE '($TRMDEF)'	    ! TRM$ (terminal) definitions
	INCLUDE '(LIB$ROUTINES)'    ! LIB$ routine names
	INCLUDE '(SMG$ROUTINES)'    ! SMG$ routine names

	CHARACTER*12 USERNAME	    ! Current username
	BYTE ENCRYPT_METHOD	    ! Password encryption method
	INTEGER*4 CURRENT_PWD(2)    ! Hashed current password
	INTEGER*4 USER_PWD(2)	    ! Hashed user-entered password
	INTEGER*2 SALT		    ! Salt value used to encrypt password
	CHARACTER*32 PASSWORD	    ! Password as entered by user
	INTEGER*2 PASSWORD_LEN	    ! Length of entered password
	INTEGER*4 KEYBOARD_ID	    ! SMG$ virtual keyboard ID
	INTEGER*4 STATUS	    ! Return status value

	STRUCTURE /ITEM_LIST_3/
	  INTEGER*2 BUFFER_LENGTH   ! Length of buffer
	  INTEGER*2 ITEM_CODE	    ! Item code
	  INTEGER*4 BUFFER_ADDRESS  ! Address of buffer
	  INTEGER*4 RETLEN_ADDRESS  ! Returned length address
	  END STRUCTURE
	RECORD /ITEM_LIST_3/ UAI_ITEMLIST(4)  ! Item list for $GETUAI

! Get current username
!
	STATUS = LIB$GETJPI(JPI$_USERNAME,,,,USERNAME)
	IF (.NOT. STATUS) CALL LIB$SIGNAL(%VAL(STATUS))

! Create virtual keyboard for password inquiry
!
	STATUS = SMG$CREATE_VIRTUAL_KEYBOARD(KEYBOARD_ID)
	IF (.NOT. STATUS) CALL LIB$SIGNAL(%VAL(STATUS))

! Fill in itemlist for $GETUAI call
!
	UAI_ITEMLIST(1).BUFFER_LENGTH  = SIZEOF(ENCRYPT_METHOD)
	UAI_ITEMLIST(1).ITEM_CODE      = UAI$_ENCRYPT
	UAI_ITEMLIST(1).BUFFER_ADDRESS = %LOC(ENCRYPT_METHOD)
	UAI_ITEMLIST(1).RETLEN_ADDRESS = 0
	UAI_ITEMLIST(2).BUFFER_LENGTH  = SIZEOF(CURRENT_PWD)
	UAI_ITEMLIST(2).ITEM_CODE      = UAI$_PWD
	UAI_ITEMLIST(2).BUFFER_ADDRESS = %LOC(CURRENT_PWD)
	UAI_ITEMLIST(2).RETLEN_ADDRESS = 0
	UAI_ITEMLIST(3).BUFFER_LENGTH  = SIZEOF(SALT)
	UAI_ITEMLIST(3).ITEM_CODE      = UAI$_SALT
	UAI_ITEMLIST(3).BUFFER_ADDRESS = %LOC(SALT)
	UAI_ITEMLIST(3).RETLEN_ADDRESS = 0
	UAI_ITEMLIST(4).BUFFER_LENGTH  = 0  ! End of list
	UAI_ITEMLIST(4).ITEM_CODE      = 0
	UAI_ITEMLIST(4).BUFFER_ADDRESS = 0
	UAI_ITEMLIST(4).RETLEN_ADDRESS = 0

! Call $GETUAI to retrieve information
!
	STATUS = SYS$GETUAI(,,USERNAME,UAI_ITEMLIST,,,)
	IF (.NOT. STATUS) CALL LIB$SIGNAL(%VAL(STATUS))

! Prompt user for password - note that conversion to
! uppercase is required, as is knowing the length of
! the entered string.
!
	WRITE (*,101) USERNAME
101	FORMAT ($,' Enter password for user ',A,': ')
	STATUS = SMG$READ_STRING(KEYBOARD_ID,PASSWORD,,,
	1 TRM$M_TM_NOECHO .OR. TRM$M_TM_CVTLOW,,,PASSWORD_LEN)
	IF (.NOT. STATUS) CALL LIB$SIGNAL(%VAL(STATUS))

! Call $HASH_PASSWORD to hash user-entered password
!
	STATUS = SYS$HASH_PASSWORD(PASSWORD(1:PASSWORD_LEN),
	1 %VAL(ENCRYPT_METHOD),%VAL(SALT),USERNAME,USER_PWD)

! Compare hashed passwords
!
	IF ((CURRENT_PWD(1) .EQ. USER_PWD(1)) .AND.
	1   (CURRENT_PWD(2) .EQ. USER_PWD(2))) THEN
	  WRITE (*,'(/A)') ' Password matches'
	ELSE
	  WRITE (*,'(/A)') ' Password does not match'
	END IF

! Clean up
!
	STATUS = SMG$DELETE_VIRTUAL_KEYBOARD(KEYBOARD_ID)
	IF (.NOT. STATUS) CALL LIB$SIGNAL(%VAL(STATUS))

	END