0

I am making a simple username and password storage program in vbs. After entering the username, I need to have a password input. I can't however, find a way to not show the input in plaintext and convert it to ****** This is what i have already:

x=MsgBox("VBScript username and password storage")
username = InputBox("Please enter your username", "Credentials storage", "Your username goes here")
passwd = InputBox("Please enter your password", "Credentials storage", "Your password goes here")

Set obj = CreateObject("Scripting.FileSystemObject")   
Const ForWriting = 2               
Set obj1 = obj.OpenTextFile("test.txt", ForWriting) 
obj1.WriteLine(username & " " & passwd)      
obj1.Close                                                                  
Set obj=Nothing   

I also tried doing this which I found as an answer on another question

Set oInput = CreateObject("ScriptPW.Password")
WScript.StdOut.Write "Enter password: "
pw = oInput.GetPassword

But when i ran it it said "ActiveX component can't create object "ScriptPW.Password"

Is there a way to hide the text in line 3 or fix my problem?

Pepe
  • 41
  • 7
  • @ArnovanBoven I updated my question sorry – Pepe Sep 23 '20 at 20:22
  • 1
    ScriptPW is additional software (or rather, a component that was on older versions of Windows). `Inputbox` by itself cannot mask passwords. – Rno Sep 23 '20 at 20:26
  • @ArnovanBoven So how else could i do it without installing software or is it not possible? – Pepe Sep 23 '20 at 20:28
  • @Lankymart No, i tried that and it gave me an error shown in my question – Pepe Sep 23 '20 at 20:31
  • 1
    @101Hacker101 see the duplicate question. It isn't possible with `Inputbox`. – Rno Sep 23 '20 at 20:42
  • @101Hacker101 it doesn’t work because you need the DLL registered with COM to access it via `CreateObject()` in VBScript. Also, the DLL is [natively available in Windows XP and Windows Server 2003 only](https://social.technet.microsoft.com/Forums/ie/en-US/9d8d148c-14e5-4654-85d5-0ec8fc8558aa/masking-vbscript-inputbox-with-scriptpwdll?forum=ITCG) so you’re best bet is download it from the internet. – user692942 Sep 23 '20 at 21:39
  • @ArnovanBoven then how else could i do it to get identical results? – Pepe Sep 24 '20 at 15:56
  • 1
    @101Hacker101 You need a workiaround such as the one in the answer. I would personally use a workaround using Powershell, but that's a matter of preference. – Rno Sep 24 '20 at 21:16

2 Answers2

1

Toyed around with this, never had a need for it. My poor man's solution so far is this. I could not figure yet out if it is possible to create a powershell object that you can use in VBScript directly, I think there's an inherent barrier there, since PS is .Net. In this case I stil return the password returned by Get-Credential as plain text, so consider this a hack. It only masks the inputbox. There are undoubtedly better solutions for this. On the plus side: this code is quite small and -importantly- does not rely on IE.

Option Explicit

Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2
Dim objShell, oExec, strOutput, strPS1Cmd

'create Powershell command
'Note that we manipulate the credentials object into a plain string
strPS1Cmd = "& { $cred = Get-Credential; Write-Output ($cred.Username + '|and-now-comes-the-password-in-plaintext|' + $cred.GetNetworkCredential().Password) } "

' Create a shell and execute powershell, pass the script    
Set objShell = WScript.CreateObject("wscript.shell")
Set oExec = objShell.Exec("powershell -windowstyle hidden -command """ & strPS1Cmd & """ ")

Do While oExec.Status = WshRunning
     WScript.Sleep 100
Loop

Select Case oExec.Status
   Case WshFinished
       strOutput = oExec.StdOut.ReadAll()
   Case WshFailed
       strOutput = oExec.StdErr.ReadAll()
 End Select

WScript.Echo(strOutput)
Rno
  • 784
  • 1
  • 6
  • 16
  • For some reason i can't seem to do anything with the data apart from echoing it, how would I write it to a file because it doesn't work the normal way? – Pepe Oct 02 '20 at 09:51
  • You could change the PS to make it output to a file, the point of this was to show an alternative way of masking the inputbox. – Rno Oct 02 '20 at 14:10
0

You can give a try for this function PasswordBox

PasswordBox.vbs

Option Explicit
Dim bPasswordBoxWait,bPasswordBoxOkay,Password
Password = PasswordBox("Veuillez taper votre mot de passe",False)
wscript.echo Password
'----------------------------------------------------------------------------'
Function PasswordBox(sTitle,FullScreen) 
    Dim oIE
    set oIE = CreateObject("InternetExplorer.Application") 
    With oIE
        If  FullScreen = True Then 
            .FullScreen = True
        Else 
            .FullScreen = False
        End if  
        .ToolBar   = False : .RegisterAsDropTarget = False 
        .StatusBar = False : .Navigate("about:blank") 
        .Resizable = False
        While .Busy : WScript.Sleep 100 : Wend 
            With .document 
                .Title = "Veuillez taper votre mot de passe * * * * * * * * * * * * *"
                With .ParentWindow 
                    .resizeto 350,100 
                    .moveto .screen.width/2-200, .screen.height/2-50 
                End With 
                .WriteLn("<html><title>Veuillez taper votre mot de passe * * * * * * *</title><body text=white bgColor=DarkOrange><center>") 
                .WriteLn(sTitle) 
                .WriteLn("<input type=password id=pass>" & _ 
                "<input type=Submit id=but0 value=Envoyer>") 
                .WriteLn("</center></body></html>") 
                With .ParentWindow.document.body 
                    .scroll="no" 
                    .style.borderStyle = "outset" 
                    .style.borderWidth = "1px" 
                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 
            End With
            .Visible = False
            .Quit 
        End With
    End Function 
'----------------------------------------------------------------------------'
Sub PasswordBox_Submit() 
    bPasswordBoxWait = False 
End Sub
'----------------------------------------------------------------------------'
Hackoo
  • 18,337
  • 3
  • 40
  • 70