English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I've built my own login system for a local small business who offers internet for free for the 1st half hour. It works perfectly, and it's okay the way it is, but I want to take it 1 step more. I want to place an algorithm that is date dependent in it. For the password, here's what I was thinking:
set value=
set /p value=
if '%choice%'=='%date% + 100 / 2' GOTO successful login

Now, I know that ^ will probably give me something other than what I want. What I want to do is remove the /s (8/22/07 would then be 82207) and add an equation to it.

The reason that I want to do this is so that it would be fairly hard to crack (they only charge $6/hour, so nobody's going to bring out the big guns) and there wouldd be a new password each day without making manual changes.

I have no idea if this is possible with a batch file. After the login is verified as correct, I want it to start another specified batch file. Please, if you can help, I'd greatly appreciate it. I'm a volunteer programmer

2007-08-22 17:08:55 · 2 answers · asked by T8r 1 in Computers & Internet Programming & Design

2 answers

This is possible using the right combination of "set" options and environment variables.
============================
First, let's get the date in the format you want. You can use some of the advanced options of "set" to choose the part of the "date" that you want and strip off the "/"s. On a commandline enter the following,

set zzdate=%date:~-10%
set zzdate=%zzdate:/=%

Then, enter just "set" at the commandline to see the environment variable values. I'm using 'zzdate' as my environment variable, you can use whatever you want. The "zz" at the front puts them at the bottom of the environment variable list so that you don't have to hunt for them.

The first line takes 10 characters starting at the end and working left (that's the ~-10 part) of the 'date'. This strips off the leading "day" characters in the normal output of "date /t"

The second line takes the value in zzdate and replaces any "/" characters with nothing (that's the /=) part.

This gives you a numerical value in %zzdate% that you can use in the rest of your batch.

For instance, on my system the current output of "date /t" is
Fri 08/24/2007

Running set zzdate=%date:~-10%
gives me zzdate=08/24/2007

and running set zzdate=%zzdate:/=%
gives me zzdate=08242007

============================
Second, let's work on some basic math in "set" using the "/a" switch. You can see details of the arithmetic operations with "set /?"

set zzz=100+100/2

gives the value of 150 because it's evaluated as 100+(100/2)

and you can use other environment variables in the expression. For example,

set zztest=100
set /a zzvalue=zztest-1

set will now show that zzvalue=99

=================
One final, important note - the 'set /a' arithmetic function does _not_ like to see leading zeros in an environment variable that is being evaluated. That's going to be a problem with the way that we're getting the date into an environment variable unless we do something about it.

These two lines check for a leading zero; and, if one is found, removes it.

set zzlead=%zzdate:~0,1%
if "%zzlead%"=="0" set zzdate=%zzdate:~-7%

==============
That's a lot of work to explain these five lines, but I like to make sure people understand the code I write,

set zzdate=%date:~-10%
set zzdate=%zzdate:/=%
set zzlead=%zzdate:~0,1%
if "%zzlead%"=="0" set zzdate=%zzdate:~-7%
set /a zzcheck=zzdate+100/2


You can use %zzcheck% as your random value to determine a successful login.

When I run these lines in a batch on my system the following happens,

First, zzdate=08/24/2007
Then, stripping "\"s, zzdate=08242007
Then, checking for and stripping leading 0, zzdate=8242007
Finally, adding (100/2) to zzcheck=8242057

=============
Another note, in your post you are using "set /p value=" which is a good way to get user input, but your next line starts out "if '%choice%' .. that should probably read "if '%value%', since you're loading the %value% environment variable with your "set /p"


Hope this gets you on your way.

2007-08-24 12:46:23 · answer #1 · answered by Kevin 7 · 6 0

without giving you a full page of code, do the following and your going to need to create temporary files to do so.

1) take in the date and output it to a file with any extension you want.
2) input into another file that output, but for each character, check to see if it's a '\'. if it is, then disregard, otherwise, output it to another file. then,
3) do a final input to your %variable% with a 'line in' from that second temp file.

i wrote something like this for a batch program and it involves some switches and those > and < symbols, but for encryption sake, it worked out swell.

if i find the time in the next 24 hours or so, i'll write it up for you. (i'm in the middle of a VB antivirus program), just email me with your email and i'll get back to you with it so i don't forget.

2007-08-22 20:53:46 · answer #2 · answered by The_Amish 5 · 0 0

fedest.com, questions and answers