need help i'm writing a small program in c and want to know how to make it password protected

Asked by nichols garrett on 2009-11-16

well i'm writing a small (really small) program in c and i'm trying to declare a password within it so that if the password isn't known it won't run the program how do i write a password into it?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
nichols garrett
Solved:
2009-11-19
Last query:
2009-11-19
Last reply:
2009-11-16
Nigel Babu (nigelbabu) said : #1

The best thing you can do is first write a password to a file and then read it from the file. That way you can change the value of the password. Please keep in mind to obfuscate the password. Use this link to see more information about handling files in C, http://c-programming.suite101.com/article.cfm/c_tutorial_file_handling_commands

can you explain the detailed method to me because i'm extremely new to this plus i'm only 16

Nigel Babu (nigelbabu) said : #3

If I give you an example program, would that solve your doubt?

it might so far i've based my entire program off of several programs already written so it can't hurt do you need my program?

 here's my program

 #include <stdio.h>

int main()
{
  char cmv540;
  printf( "declare password first\n");
  gets(cmv540);

  if(!strcmp(cmv540))
  printf("I'm alive! Beware\n");
  else
  printf("incorrect password\n");

  return 0;
}

Nigel Babu (nigelbabu) said : #6

I dont this would work, coz cmv540 is only declared, but not defined. When you compare strings, you need 2 strings, one original and one to compare with. Gimme a day, I'll write a program and you can check it out

ok thank you for your help

i think i got it down thanks for your help anyway though here's my new program...

#include <stdio.h>

int mult ( int x, int y );

int main()
{
  int password;
  int x;
  int y;

  printf( "please enter the password: \n" );
  scanf( "%d", &password);
  if(password==1211) {
  printf( "please enter two numbers to be multiplied:\n");
  scanf( "%d", &x );
  scanf( "%d", &y );
  printf( "The product of your two numbers is %d\n", mult( x, y ) );
  getchar();
}
  else{
  printf("wrong password get the hell off my calculator\n");}
}
int mult (int x, int y)
{
  return x * y;
}