none
How can I save user and passwords in powershell to a text file? RRS feed

  • Question

  • Ive been building a bat file and trying to incorp powershell in for this very reason to cover the input. However im having an issue connecting the script to my user and password databases that i have set. Will someone please take a look and let me know how i can fix it? Thanks. -E

    :createaccount
    color 1a
    echo.
    cls
    title Registration
    echo ================================================
    echo                   NEW ACCOUNT          
    echo ================================================
    echo.
    set /p "userl=Email:"
    set "psCommand=powershell -Command "$pass1 = read-host 'Enter Password' -AsSecureString ; ^
         $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass1); ^
               [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
    for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p

    set "psCommand=powershell -Command "$ssn1 = read-host 'Last 4 SSN (Used for Password Recovery)' -AsSecureString ; ^
         $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ssn1); ^
               [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
    for /f "usebackq delims=" %%p in (`%psCommand%`) do set Last4SSN=%%p
    echo.
    echo %userl% >> %userl%.user
    echo %passl% >> %passl%.pass
    echo %ssn1% >> %ssn1%.ssn
    goto login

    :login
    Title Account Login
    color 1a
    echo.
    cls
    echo ================================================
    echo                      LOGIN          
    echo ================================================
    echo.
    set /p "userm=Email:"
    set "psCommand=powershell -Command "$passm = read-host 'Enter Password' -AsSecureString ; ^
         $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($passm); ^
               [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
    for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
    echo.
    echo.
    if exist "C:\account\%userl%.user" goto success
    if exist "C:\account\%passl%.pass" goto success
    if not exist "C:\account\%userl%.user" goto forgotpwd
    if not exist "C:\account\%passl%.pass" goto forgotpwd

    :success
    Title Welcome!
    cls
    echo You have successfully logged in!
    pause
    goto dashboard
     

    Also, tying to do password recovery. when they signup the last 4 of their ssn are saved and then recalled for password recovery. In a batch file i can use something like this to determine if they are who they say but how to i get the program to display their password for them from the password file after they confirm their identity?

    :forgotpwd
    cls
    color 1c
    title Forget Your Password?
    echo [1a:Switch User] [2a:Logoff] [3a:Help] [4a:Exit]
    echo.
    echo ================================================
    echo              FORGET YOUR PASSWORD?             
    echo ================================================
    echo.
    echo. 
    echo Press [x] for Password Recovery 
    echo or press [Enter] to return to Login
    echo.
    set /p opt=Select:
    if %opt%==x goto recoverpwd
    if %opt%==1a goto switchuser
    if %opt%==2a goto logoff
    if %opt%==3a goto help
    if %opt%==4a exit
    if not %opt%==x goto login
    if not %opt%==1a goto login
    if not %opt%==2a goto login
    if not %opt%==3a goto login
    if not %opt%==4a goto login

    :recoverpwd

    echo ================================================
    echo                PASSWORD RECOVERY            
    echo ================================================
    echo.
    set /p "ssnm=Last 4 SSN:"
    echo.
    if exist "C:\account\%ssnl%.ssn" goto changepwd
    if not exist "C:\account\%ssnl%.ssn" goto error
    echo.
    echo.

    • Moved by jrv Monday, October 2, 2017 8:48 PM better forum
    • Moved by Bill_Stewart Tuesday, November 7, 2017 10:42 PM This is not "fix/debug/rewrite my script for me" forum
    Monday, October 2, 2017 4:22 PM

All replies

  • This is a PowerShell forum.  You have posted a batch script.  This forum does not support batch scripting.

    Batch is obsolete and cannot do most things in modern Windows.  You should learn PowerShell.

    I will move this to a better forum for batch.


    \_(ツ)_/

    Monday, October 2, 2017 8:48 PM