Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Issues masking a password in VB

Posted on 2013-11-03
2
Medium Priority
?
371 Views
Last Modified: 2013-11-05
I have written some code in VB script that does not always present the same dialog box. The attached code should prompt for a password and not allow a blank password. Then prompt to confirm that password, again not allowing a blank. Then compare the 2 and loop if they do not match, or (remarked out) change the password of the stated user (pphread).

the issue I have is that when executed I get a dialog box stating "Please enter the new password for Pphread.". I enter a password and then I should get a prompt stating "Please confirm the password for Pphread.".

Sometimes I get the confirmation prompt and sometime I get just a blank dialog box with a text box and submit button. No text stating "Please confirm the password for Pphread."

It appears to be random as to when it is correct and when it is not.

I have attached the code and a picture of the blank dialog box.

Any suggestions would be great.

Currently testing on Windows 7/64bit w/IE10, but will need to run on Windows XP SP3 32bit w/ IE9

thanks

Option Explicit 
Dim ObjFSO, user, strComputer, X, Y, Z, strPW, strPWConf, oIE, bPasswordBoxOkay, bPasswordBoxWait
strComputer = "LocalHost"
Set ObjFSO = CreateObject("Scripting.FileSystemObject") 

Set user = GetObject("WinNT://" & strComputer & "/Pphread,user") 
		REM strPW = PasswordBox("Please enter the new password for Pphread.") 
		REM strPWConf = PasswordBox("Please confirm the password for Pphread.") 

Do While X = 0
	Do While Y = 0
		strPW = PasswordBox("Please enter the new password for Pphread.") 
		If strPW = "" Then
			Wscript.Echo "You must enter a password."
		Else
			Exit Do
		End If
	Loop

	Do While Z = 0
		strPWConf = PasswordBox("Please confirm the password for Pphread.") 
		If strPWConf = "" Then
			Wscript.Echo "You must confirm the password."
		Else
			Exit Do
		End If
	Loop

	If strPW = strPWConf Then
		Wscript.Echo "Passwords Match."
		Exit Do
	Else
		Wscript.Echo "The Passwords do not match, Please Re-enter."
	End If
Loop
	REM If strPW = "" Then
		REM Wscript.Echo "Blank Passwords are note allowed."
		REM WScript.Quit 1
	REM End If

	REM If strPW = strPWConf Then
		REM Wscript.Echo "Passwords Match."
	REM Else
		REM Wscript.Echo "The Passwords do not match, Please Re-enter."
		REM WScript.Quit 1
	REM End If
	
Wscript.Echo "test"
REM user.setpassword strPW
REM user.setinfo 


Function PasswordBox(sTitle) 
  set oIE = CreateObject("InternetExplorer.Application") 
  With oIE 
    .FullScreen = False 
    .ToolBar   = False : .RegisterAsDropTarget = False 
    .StatusBar = False : .Navigate("about:blank") 
    While .Busy : WScript.Sleep 200 : Wend 
    With .document 
      With .ParentWindow 
        .resizeto 500,100 
        .moveto .screen.width/2-200, .screen.height/2-50 
      End With 
      .WriteLn("<html><body bgColor=Silver><center>") 
      .WriteLn( sTitle ) 
      .WriteLn("<input type=password id=pass>  " & _ 
               "<button id=but0>Submit</button>") 
      .WriteLn("</center></body></html>") 
      With .ParentWindow.document.body 
        .scroll="no" 
        .style.borderStyle = "outset" 
        .style.borderWidth = "3px" 
      End With 
      .all.but0.onclick = getref("PasswordBox_Submit") 
      .all.pass.focus 
      oIE.Visible = True 
      bPasswordBoxOkay = False : bPasswordBoxWait = True 
      On Error Resume Next 
      While bPasswordBoxWait 
        WScript.Sleep 100 
        if oIE.Visible Then bPasswordBoxWait = bPasswordBoxWait 
        if Err Then bPasswordBoxWait = False 
      Wend 
      PasswordBox = .all.pass.value 
	  .Quit
    End With ' document 
    .Visible = False 
	.Quit
  End With   ' IE 
End Function 


Sub PasswordBox_Submit() 
  bPasswordBoxWait = False 
End Sub

Open in new window

IE-blank-submit.jpg
0
Comment
Question by:pphreadr
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 39621039
Very strange indeed. I have confirmed the behaviour on W7/64,IE10/32. It may be a bug, I haven't been able to establish the reason behind it ("F12 dev tools" shows the text is actually there but invisible) but I did find a solution I think.

It works consistently for me (with a reasonable amount of testing) after changing WriteLn to Write (only the last one I left alone) so it seems the linefeeds in between the html tags are messing with the document somehow:
      .Write("<html><body bgColor=Silver><center>") 
      .Write( sTitle ) 
      .Write("<input type=password id=pass>  " & _ 
               "<button id=but0>Submit</button>") 
      .WriteLn("</center></body></html>") 

Open in new window

It works the same as concatenating the string all into one Writeln.
      .WriteLn("<html><body bgColor=Silver><center>" & sTitle & "<input type=password id=pass>  " & "<button id=but0>Submit</button>" & "</center></body></html>") 

Open in new window

Of course you will still need to test on IE9 anyway, I haven't got that version available.
0
 

Author Closing Comment

by:pphreadr
ID: 39624266
robert_schutt I have given you the credit seeing as you came up with the fix. Now I have to enter another question because the script does not work on Windows XP. The line:

<code>Set user = GetObject("WinNT://" & strComputer & "/" & strUser & ",user") </code>

Causes Windows XP to error with:

You were not connected because a duplicate name exists on the network. Go to Control Panel and change the computer name and try again.

I will be posting another question to see if this can be fixed. Thank s for this fix.

Pphread

The error is false as the computer name is not a duplicate.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question