Okay so heres what I'm trying to do. I'm trying to make a batch file with a user input for a login. I would like to have the ability to create a new account. I have an idea, I just don't know how to go around implementing it. I have the user input his desired username and password and have it save to a text document like so:
#echo off
set /p user=Enter your desired username:
set /p pass=Enter your desired password:
echo %user% >> log.txt
echo %pass% >> log.txt
That works fine for me, but now what I would like to do is call up those two lines so that when they entered the correct username and password it will take them to their menu.
I know for a fact the the call won't work well with this. Is there any way to do what I'm trying to do?
P.S. I am aware that the txt file is not secure. I have ways around that.
You may do this to recover the saved values:
(
set /P savedUser=
set /P savedPass=
) < log.txt
This way:
if "%user%" == "%savedUser%" if "%pass%" == "%savedPass%" goto accessGranted
Another way to save the values is this:
echo set savedUser=%user%> log.bat
echo set savedPass=%pass%>> log.bat
and to recover the saved values:
call log
I'm decently proud of this :) This is pretty much a complete overhaul of your method.
This has two different files: login.bat which handles the login and login2.bat which handles the registration.
login.bat:
#echo off
choice /c:RL /m "Choose an option: Register (R) or Login (L).:
if errorlevel 2 goto login
if errorlevel 1 goto register
:register
start /wait C:\[path]\login2.bat
cls
goto login
:in
cls
echo Welcome %u%
echo.
echo Bla Bla Bla or start "a program"
pause
exit
:login
set /p u=Username
set /p p=Password
and login2.bat:
#echo off
:a
set /p a="Choose a Username"
set /p b="Choose a Password"
echo.
choice /m "Are you sure you would like your Username to be %a% and your Password to be %b%?"
if errorlevel 2 goto a
set q="if %%u%% equ %a% if %%p%% equ %b% goto in"
for /f "tokens=*" %%I in (%q%) do set m=%%I
echo %m% >>C:\[path]\login.bat
exit
The reason why :in, the label which handles what happens after you login successfully has to be in the middle instead of at the end of login.bat is so that the username/password combinations could be appended to the :login label. Obviously you could add other embellishments and change the name of the files, but this is my basic design.
Hope this helps!
This is what I do
#echo off
:: some code here
set /p username=please create a username:
set /p password=please create a password:
echo %username%>username.txt
echo %password%>password.txt
This will create a text file for both your username and password
I hope this helped. :)
Related
I've been trying to get this code to work...
I've tried re doing the code... to no avail also, the code below is a bit big...
:ST
if exist password.txt goto login
if not exist password.txt goto signup
:login
set /p user=<username.txt
set /p pass=<password.txt
set /p answer=Username:
if %answer% = %user% goto p1
if NOT %answer% = %user% goto errlog111
exit
:p1
set /p answer=Password:
if %answer%=%pass% goto
if NOT %answer% = %pass% goto errlog111
echo success
pause
exit
:signup
title Username needed for account creation! / Newex / Unregistered
set /p answer=Username:
echo %answer% > username.txt
cls
set /p answer=Password:
echo %answer% > password.txt
cls
echo Account created!
goto login
exit
:errorlog111
echo Username / Password incorrect!
pause
goto login
So, what I want is for it to check the contents of password.txt, (or username.txt) for what the user inputs, and if the user inputs the right thing, it goes on to the next thing. However, if they get the password, or username wrong then I want it to say "Username / Password wrong!" but for some reason when I enter the username, the batch file just closes! Please help!
if %answer% = %user% goto p1
The correct syntax is to use == or EQU.
Better syntax is
if "%answer%" == "%user%" goto p1
the quotes protect against some illegal inputs and where the arguments contain certain characters like , ; and would be advised for any comparison between strings.
Note that if /i ... makes the comparison case-insensitive (for future reference)
Also - a hard-to-see error
echo %answer% > username.txt
will include the space which follows the value of answer into the file
> username.txt echo %answer%
will not include this (presumably) unwanted space.
My batch script does the following:
user types in username and is added to a variable
trick to ask for password (hides input from user) and adds to variable
checks username and password authentication for domain GROUP using "net user" command
If user is found in set group, continue to map drive.
If user is not part of group restart at beginning
This script works when the username is found.
This script works when a username is found in a group
The problem is if the username is NOT FOUND.
When the user is NOT FOUND, it reports the "More help is available by typing NET HELPMSG 2221."
It just sits there and does not continue to prompt or anything.
I echoed the errorlevel and it comes out to 0, and reports the 0. However it still just sits there never reaching command prompt or going where the GOTO tells it.
I have put in errorlevels and I am unsure why it is stuck after the error message and does not continue. It is as if the batch script is not releasing from somewhere.
#echo off
:Question
Echo.
Echo.
SET /P HelperName=Enter Witness' Name:
Echo.
If %HelperName% EQU %Username% GOTO SameUserName
cls
echo hP1X500P[PZBBBfh#b##fXf-V#`$fPf]f3/f1/5++u5>%temp%\ftp.com
set /p password=What is your password? <nul
for /f "tokens=*" %%i in ('%temp%\ftp.com') do set "password=%%i"
del %temp%\ftp.com
cls
set i=0
set group=WGD
set user=%HelperName%
echo Checking if %user% is member of %group%...
for /f %%f in ('"net user %user% /domain | findstr /i %group%"') do set /a i=%i%+1
if %i% gtr 0 (goto :member)
:nomember
echo %user% is not member of %group% Please Try Again
goto :question
:member
net use L: \\10.10.10.10\foldernamehere\TEMP /user:wgd\%helpername% %password%
if [%errorlevel%]==[0] goto deletedrive
goto error
:deletedrive
net use /delete L:
goto start
It is as if the script in still in another function.
Well it seems like I was not waiting long enough for the message to finish. It hangs for a bit, then continues on through the script. The wait however for the help message to clear is a little long, if you know how to clear faster please let me know.
So I am experimenting and trying to get better at using batch but I'm stuck on an issue, and I cant figure it out. The save/load allows the user to input a password and save it to the blah.blah, then later load it using the password. The problem is I want the program to recognize if the user has a password and if they dont, it will give them the option to exit or make a new password.
:passwordwant
cls
set /p "passwant=Enter your new password: "
(
echo %passwant%
)>save.sav
goto :passwordload
pause >nul
:passwordload
cls
echo Enter password to enter the programme
set /p "pass=>"
if %pass%== %passwant% goto :home
<save.sav(
set /p pass=
)
You can use if exist to determine if a file exists (or if not exist to determine if it doesn't).
if not exist save.sav (
echo Password not found
REM If you're using Windows XP or earlier, you need to use set /p instead of choice
choice /c:NQ /M "Press N to create a password. Press Q to quit."
if %errorlevel% equ 0 goto :passwordwant
if %errorlevel% equ 1 exit /b
)
I am attempting to write a batch script that adds new users to a machine using user prompts to get the information. I am at the point where the user gets created correctly, but the "Full Name" and "Description" fields don't populate, no matter what I try. I can't seem to get it to pass the %fullname% variable into either the net user command or the wmic command. If I just type quoted text into either spot it adds the information properly. Also if there's a better way to do echos like that it would be appreciated, takes up too many lines IMO. :)
:User
echo.
echo Please Input Username...
echo.
set /p username=Username:
echo.
echo Please Confirm Username...
echo.
set /p confirm=Username:
if '%username%' == '%confirm%' (
echo.
echo Please Input User Full Name...
echo.
set /p fullname=Full Name:
echo.
echo Please Input User Description...
echo.
set /p description=Description:
echo Creating %username%...
net user %username% * /add /active:yes /fullname:%fullname% /comment:%description% /passwordchg:no /expires:never
wmic useraccount where "Name='%username%'" set PasswordExpires=FALSE
wmic useraccount where "Name='%username%'" set FullName=%fullname%
This script creates the user just fine, but the fullname and comment fields are blank.
Problem solved. Apparently the parentheses for my if statement were messing everything up. The fullname and description variables were blank for whatever reason. I guess you can't do a set inside an if statement?
No matter, changing to this has solved the problem and it works perfectly now.
:User
echo.
echo Please Input Username...
echo.
set /p username=Username:
echo.
echo Please Confirm Username...
echo.
set /p confirm=Username:
if '%username%' == '%confirm%' goto User1
goto User
:User1
echo.
echo Please Input User Full Name...
echo.
set /p fullname=Full Name:
echo.
echo Please Input User Description...
echo.
set /p description=Description:
pause
echo Creating %username%...
net user %username% * /add /active:yes /fullname:"%fullname%" /comment:"%description%" /passwordchg:no /expires:never
wmic useraccount where "Name='%username%'" set PasswordExpires=FALSE
i have been formulating and doing a batch program that enables the user to enter his password,just like that, and i seem to arrive at nothingness, can anybody show me how to create a batch program that enables the user to enter his password?and run a specific program when log in is successfull, by the way, i am using windows xp sp2
set /p "PASSWORD=Enter your password: "
I use the quotes so I can show the trailing space in the batch file. Otherwise it's not necessary; any trailing spaces will be echoed into the output.
set /? shows a number of ways of manipulating variables in cmd.exe
Here's something that works for me...
#echo off
:loginPASS
set /p password=Password:
if %password% == qwerty goto loginsuccessful
if %password% == %password% goto loginfailed
:loginfailed
echo Login failed, password was incorrect!
pause
cls
goto login
:loginsuccessful
echo LOGIN SUCCESSFUL!
cd <location of file (dont include its name) example: C: /Users/YOURUSERNAME/desktop>
<type in file name here>
if you want to make a username input too, then delete the loginPASS section make a new one called loginUSER and type in this:
:loginUSER
set /p username=Username
cls
if %username% == Admin goto AdminLogin
if %username% == Bob goto BobLogin
if %username% == %username% goto NoUsername
make a new section called NoUsername
:NoUsername
echo User not found, check your username again.
pause
cls
goto loginUSER
this will tell the user if they entered the wrong username.
after that make a new section for 1 of the users and name appropriately.
in this case you will name it AdminLogin.
After that repeat loginPASS and make the password for the user.
The whole code should look something like this:
#echo off
:AdminLogin
set /p password=Password:
if %password% == 158468 goto loginsuccessful
if %password% == %password% goto loginfailed
:loginfailedADMIN
echo Login failed, password was incorrect!
pause
cls
goto AdminLogin
:loginsuccessfulADMIN
echo LOGIN SUCCESSFUL!
cd <location of file (dont include its name) example: C: /Users/YOURUSERNAME/desktop>
<type in file name here>
pause
exit
You will want to make seperate login sections for each user.
Hope this helps!
P.S There might be other ways but this is what i use.