I'm writing a password program to keep people out of my stuff who share this computer, and I need to know how you open another program from another. For example, I need my game, Red Alert 2, to come up when I put in the pass. How would I do this?
I'm writing a password program to keep people out of my stuff who share this computer, and I need to know how you open another program from another. For example, I need my game, Red Alert 2, to come up when I put in the pass. How would I do this?
Its very easy. I assume you know how to write a password checker, so when the password is correct, use the ShellExecute API to run the red alert exe.
Check the FAQ.
use "system( char * )"
system("C:\\path\\redalert2.exe");
If your trying to secure your computer, that should be a job of the operating system. I know there are programs out there, that can encrypt part of your hard drive, and they will only be un encryped with a password, that may be more effective, than your program
Doesn't worK:
C:\Dev-C++\Untitled1.cpp: In function `int main()':
C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\G'
C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\W'
C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\C'
C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\R'
Execution terminated
Are you using a single backslash, or are you using 2? Should be 2 if you want to represent a directory structure/filename. As in the earlier example.Originally posted by Unregistered
Doesn't worK:
C:\Dev-C++\Untitled1.cpp: In function `int main()':
C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\G'
C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\W'
C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\C'
C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\R'
Execution terminated
Post code if this doesn't help.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
include conio.h and link to conio.o
system() lives in stdlib.hOriginally posted by Quantrizi
include conio.h and link to conio.o
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Phew, finally got it working. But there is one feature I can't figure out. I want to get it to record whenever someone tries to get into the applications, as you can see in the code. Any ideas why it isn't working? Feel free to make modifications and use it yourselves, by the way, just don't take out the first couple lines of comments. I may make an editor for it and dsitribute it.
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
#include <time.h>
#include <process.h>
#include <fstream.h>
char password[50];
char passin[50];
int prog;
int main(void)
{
ofstream log("accesslog.txt,ios::app");
time_t rawtime;
time ( &rawtime );
log<<"Attempted access on: %s "<<ctime(&rawtime)<<".\n";
log.close();
int select;
srand (time(NULL) );
select = rand()%8;
if (select==0)
strcpy (password,"jeff");
if (select==1)
strcpy (password,"ssgnxf");
if (select==2)
strcpy (password,"junior");
if (select==3)
strcpy (password,"sden");
if (select==4)
strcpy (password,"matt_pants");
if (select==5)
strcpy (password,"fern");
if (select==6)
strcpy (password,"wifey");
if (select==7)
strcpy (password,"it_tastes_like");
if (select==8)
strcpy (password,"chicken");
do {
cout << "Please enter the correct password.\n";
cin >> passin;
} while (strcmp (passin,password) != 0);
cout<<"Confirmed. You are cleared to enter.\n";
cout<<"\nWhich program would you like to run?\n1. Command and Conquer: Red Alert 2\n2. Nothing.\n\n";
cin>>prog;
if(prog==1)
{
system("D:\\Games\\Westwood\\CnC\\Ra22.exe");
}
if(prog==2)
{
return 0;
}
}
try this.
Code:#include <stdlib.h> #include <iostream.h> #include <string.h> #include <time.h> #include <process.h> #include <fstream.h> char password[50]; char passin[50]; int prog; int main(void) { ofstream log("accesslog.txt,ios::app"); time_t rawtime; time ( &rawtime ); log<<"Attempted access on: %s "<<ctime(&rawtime)<<".\n"; log.close(); int select; srand (time(NULL) ); select = rand()%8; switch(select) { case 0: strcpy (password,"jeff");break; case 1: strcpy (password,"ssgnxf");break; case 2: strcpy (password,"junior");break; case 3: strcpy (password,"sden");break; case 4: strcpy (password,"matt_pants");break; case 5: strcpy (password,"fern");break; case 6: strcpy (password,"wifey");break; case 7: strcpy (password,"it_tastes_like");break; case 8: strcpy (password,"chicken"); } do{ cout << "Please enter the correct password.\n"; cin >> passin; }while (strcmp (passin,password) != 0); cout << "Confirmed. You are cleared to enter.\n\nWhich program would you like" << "to run?\n1. Command and Conquer: Red Alert 2\n2. Nothing.\n\n"; cin >> prog; if(prog==1) system("D:\\Games\\Westwood\\CnC\\Ra22.exe"); else return 0; }
Thanks, that's much better organized. However, it still doesn't make a log file that I can use to see when people tried to get into the game. Any ideas here?
>>However, it still doesn't make a log file that I can use to see when people tried to get into the game. Any ideas here?
The log file would probably be made in the folder where you are executing/creating the programs.
eg-> "C:\PROGRAMMING\C++" and not in the folder where the game is.
-
change
ofstream log("accesslog.txt,ios::app"); to this
ofstream log("accesslog.txt" , ios::app);
Hard coding passwords like you have done is bad practice, I'm afraid. Anyone can hexdump your program and find out your passwords. Try encrpyting them a bit within your source.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]