Announcement

Collapse
No announcement yet.

Hide/Encrypt prompted password

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hide/Encrypt prompted password

    Does anyone know how to hide or encrypt a prompted password?

    For example:

    strPass = InputBox("Enter your password:")

    But when you type the password it will should up as "********"

  • #2
    Re: Hide/Encrypt prompted password

    I've found ways to do this here:

    http://www.microsoft.com/technet/scr...5/hey0204.mspx

    But I don't want to have any extra files that i'll need floating around with the script...

    Comment


    • #3
      Re: Hide/Encrypt prompted password

      And what's wrong w/ the ScriptPW bit? No extra files. Built-in to WXP and W2K3 and ???
      Cheers,

      Rick

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

      Comment


      • #4
        Re: Hide/Encrypt prompted password

        Ah yeah...it error's out if it's not run from the command line for me...so I have to open a command prompt and use "cscript runas.vbs" Is there a way around that?

        Edit*

        So yes I could make a bat file that will call the script...but I wanted to see if there was a way that I wouldn't have to do that...we also have a mixed environment here of XP and 2000, which it says only works with xp and 2k3.
        Last edited by ekrengel; 2nd July 2007, 21:02.

        Comment


        • #5
          Re: Hide/Encrypt prompted password

          Originally posted by ekrengel View Post
          I've found ways to do this here:
          http://www.microsoft.com/technet/scr...5/hey0204.mspx
          But I don't want to have any extra files that i'll need floating around with the script...
          In a previous thread from you, with the subject "modify vbs", you already showed that it is possible to open a new blanc HTML-page and write HTML code to it from the vbscript it self.
          That is exact what the script below is doing. It combines the two files (html + vbs) showed in 'The Scripting Guys Answer'.
          It can workt interactive with the HLML page w/out getting security warnings you normally get when opening a seperate HTML page containing scriptcode)

          Code:
          sPasswrd = passwordbox()
          
                 msgBox(sPasswrd)
          
          wscript.quit
          
          
          '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
          Function PasswordBox()
            'http://www.dbforums.com/archive/index.php/t-959294.html
            set oIE = CreateObject("InternetExplorer.Application")
            
            With oIE
             .RegisterAsDropTarget = False
             .Resizable = False : .FullScreen = True
             .width = 400 : .height = 100
             .Navigate "about:blank"
             
             Do Until .ReadyState = 4 : WScript.Sleep 100 : Loop
             
             .document.open
             .document.write _
               "<html><head><" & "script>bboxwait=true;</" _
               & "script><title>Password _</title></head>"_
               & "<body bgColor=Silver scroll=no" _
               & " style='border-Style:outset;border-" _
               & "Width:3px'>" _
               & "<center><b>Enter Password : </b>" _
               & "<input type=password id=pass><p>" _
               & "<button onclick='bboxwait=false;'>" _
               & " validate </button>" _
               & "</center></body></html>"
             .document.close
          
             Do Until .ReadyState = 4 : WScript.Sleep 100 : Loop
          
             'set window focus
             .Visible = True
             CreateObject("Wscript.Shell").Appactivate "http:// - Password _"
              With .document
                oIE.left = .parentWindow.screen.width \ 2 - 200
                oIE.top = .parentWindow.screen.height\ 2 - 100
                .all.Pass.focus
                PasswordBox = "CANCELLED"
          
                On Error Resume Next
                Do While .parentWindow.bBoxWait
                  if Err Then Exit Function
                  WScript.Sleep 500
                Loop
                
                oIE.Visible = false
                PasswordBox = .all.pass.value
              End With ' document
            End With '---(oIE)---
          
            'Switch back focus (tip!)
            CreateObject("Wscript.Shell").Run chr(34),0,false
          
          End Function
          Can you test whether this script works also on Windows 2000 computers. (?)

          \Rems



          - - - EDIT - - -

          According to Windows Task Manager, the complete title string for the HTTP-page titled "Password _" is: http:// - Password _ - Microsoft Internet Explorer
          The line CreateObject("Wscript.Shell").Appactivate("task_name") is used here to set the 'desktop focus' to this window



          Pitfalls of Using the AppActivate Method

          To determine which application to activate, AppActivate compares the title parameter submitted to the method with the title string of each running application.
          1. If no exact match exists, any application whose title string begins with the pattern contained in the title variable is activated.
          2. If no application is found, any application whose title string ends with the pattern contained in the title variable is activated.

          Although generally useful, the AppActivate method has several drawbacks:
          • You must know the exact title during design time. If the script runs on a localized version of Windows, you must first specify the constants with the window titles.
          • If a program changes its title text, it becomes difficult or impossible to use AppActivate.
          • If the window is minimized, you can't make the window style normal or maximized.
          • If several windows use the same window title, you can't use the title text to detect a specific window. If more than one instance of an application named by title exists, AppActivate activates the first instance (as determined by an internal, open window list).
          Last edited by Rems; 3rd July 2007, 18:23.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: Hide/Encrypt prompted password

            Hey, I found the original script too
            (nice)

            Code:
            '/// ----------------------------------------------------------
            '/// http://members.cox.net/tglbatch/wsh/PasswordBox.vbs.txt
            '///
            '/// Example of how to use the   Function : 
            '/// ----------------------------------------------------------
            
            sUser = CreateObject("WScript.Network").UserName
            
            wsh.echo "You entered: ", _
                     Join(PasswordBox("Enter UID and password", _
                          sUser), ", ")
            
            wscript.quit
            
            
            
            Function PasswordBox(sPrompt, sDefault)
              ' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
              ' A function to present a Password dialog in a VBS (WSF) 
              ' script
              ' Requires WScript version 5.1+
              ' Tom Lavedas <[email protected]>
              ' with help from and thanks to Joe Ernest and 
              ' Michael Harris
              '
            
              set oIE = CreateObject("InternetExplorer.Application")
              With oIE
            ' Configure the IE window
                .RegisterAsDropTarget = False   
                .Resizable = False : .FullScreen = True
                .width = 400       : .height = 220
                .Navigate "about:blank"
                Do Until .ReadyState = 4 : WScript.Sleep 100 : Loop
            ' Create the password box document
                With .document
                  oIE.left = .parentWindow.screen.width \ 2 - 200
                  oIE.top  = .parentWindow.screen.height\ 2 - 100
                  .open
                  .write "<html><head><" & "script>bboxwait=true;</" _
                       & "script><title>Password _</title></head>"_
                       & "<body bgColor=silver scroll=no " _
                       & "language=vbs style='border-" _ 
                       & "style:outset;border-Width:3px'" _
                       & " onHelp='window.event.returnvalue=false" _
                       & ":window.event.cancelbubble=true'" _
                       & " oncontextmenu=" _ 
                       & "'window.event.returnvalue=false" _
                       & ":window.event.cancelbubble=true'" _
                       & " onkeydown='if ((window.event.keycode>111)"_
                       & " and  (window.event.keycode<117)) or" _
                       & " window.event.ctrlkey then" _
                       & " window.event.keycode=0" _
                       & ":window.event.cancelbubble=true" _
                       & ":window.event.returnvalue=false'" _
                       & " onkeypress='if window.event.keycode=13" _
                       & " then bboxwait=false'><center>" _
                       & "<div style='padding:10px;background-color:lightblue'>" _
                       & "<b>&nbsp" & sPrompt & "<b>&nbsp</div><p>" _
                       & "<table bgcolor=cornsilk cellspacing=10><tr><td>" _
                       & " <b>User:</b></td><td>" _
                       & "<input type=text size=10 id=user value='" _
                       & sDefault & "'>" _
                       & "</td><tr><td> <b>Password:</b></td><td>" _
                       & "<input type=password size=12 id=pass>" _ 
                       & "</td></tr></table><br>" _
                       & "<button onclick='bboxwait=false;'>" _
                       & "&nbsp;Okay&nbsp;" _
                       & "</button> &nbsp; <button onclick=" _
                       & "'document.all.user.value=""CANCELLED"";" _
                       & "document.all.pass.value="""";" _
                       & "bboxwait=false;'>Cancel" _
                       & "</button></center></body></html>"
                  .close
                  Do Until .ReadyState = "complete" : WScript.Sleep 100 : Loop
                  .all.user.focus
                  .all.user.select ' Optional
                  oIE.Visible = True
                  CreateObject("Wscript.Shell")_
                    .Appactivate "http:// - Password _"
                  PasswordBox = Array("CANCELLED")
                  On Error Resume Next
                  Do While .parentWindow.bBoxWait
                    if Err Then Exit Function
                    WScript.Sleep 100
                  Loop
                  oIE.Visible = False
                  PasswordBox = Array(.all.user.value, _
                                      .all.pass.value)
                End With ' document
              End With   ' IE
            
              'Switch back focus (tip!)
              CreateObject("Wscript.Shell").Run chr(34),0,false
            
            End Function
            
            
            ' |------------------
            ' |  note:
            ' |------------------
            ' | The script in the link above requires IE 5.5+, if you want the script
            ' | to work on IE 5.01 as well, remove the following two lines (this will
            ' | re-enable right-click menu on the dialog):
            ' |
            ' | &  " onContextmenu='window.event.cancelbubble=true" _
            ' | & ":window.event.returnvalue=false'" _
            ' |
            ' | (from: http://www.codecomments.com/message163200.html)
            The blue text is what I added to the original script .

            \Rems

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Hide/Encrypt prompted password

              Thanks Rems! This is just what I was looking for.

              Comment


              • #8
                Re: Hide/Encrypt prompted password

                Although where is the password stored? I see that it is echoing the password and username...but how would I just get it to echo the password? Well not really echo, just put it to where the password needs to be...

                Comment


                • #9
                  Re: Hide/Encrypt prompted password

                  It is stored in an array 'PasswordBox'. The array is created by this line(s) at the end of the function:
                  PasswordBox = Array(oIE.document.all.user.value, oIE.document.all.pass.value)

                  That is how a script function should function -> called and return one string or one array back to the script.

                  Now back to the main part of the script, the 'wsh.echo' line uses the function 'Join' to create one string of the array lines returned from the script function.
                  You could then use the function 'Split' to break the string into an array again. But that would not realy be nessesery.

                  This shows how you can create the variables strName and strPass:
                  Replace the wsh.echo lines from the previous script with the lines below:
                  Code:
                  sUser = CreateObject("WScript.Network").UserName
                  
                  arNamePass = PasswordBox("Enter UID and password",sUser)
                  'shift values from array:
                   strName = arNamePass(0)
                   strPass = arNamePass(1)
                  
                     msgBox "input Name    " & vbTab & ":  " & strName & vbNewLine & _
                                  "input Password" & vbTab & ":  " & strPass
                  \Rems

                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  __________________

                  ** Remember to give credit where credit's due **
                  and leave Reputation Points for meaningful posts

                  Comment


                  • #10
                    Re: Hide/Encrypt prompted password

                    Ahh I see, thanks Rems. Why would you use an array over just setting it as a string to begin with in the input box?

                    Comment


                    • #11
                      Re: Hide/Encrypt prompted password

                      Why would you use an array over just setting it as a string to begin with in the input box?
                      Because this is made a Function and not a Sub.
                      This function here is a dedicated variant of the standard single Inputbox function.
                      A Function is there for one purpose, they can be called from a script with input and returns ONE output. Just like all the built-in VBScript functions do.

                      You can change the Function to a Sub if you like, and then bring the two variables from the Sub's double inputboxes back to the main script.

                      But Functions are more valueable to me than Subs because they are complete (they suppost to be independed from the main script) and can be used just like the way a build-in function can be used.
                      You can use Functions in other scripts w/out the chance of making nesseray modifications first. The only thing to concern about is how the correct syntax must look like to call the function.

                      B.t.w. If you keep a script and code snippets repository for your self,
                      then this can be a handy search tool to find Functions and sub within all of your saved scripts: Create script index.vbs

                      \Rems

                      This posting is provided "AS IS" with no warranties, and confers no rights.

                      __________________

                      ** Remember to give credit where credit's due **
                      and leave Reputation Points for meaningful posts

                      Comment


                      • #12
                        Re: Hide/Encrypt prompted password

                        Thanks Rems.

                        Comment

                        Working...
                        X