开发者

log in batch program

开发者 https://www.devze.com 2023-01-15 23:07 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消