Fix my program

N

Nomen Nescio

Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}

Thank you for fixing my program! Also please do not tell
anyone the password, it is copywrited.

-- Nth Complexity --
-- Have A Nice Day! --
"However, these criteria, admirable as they are, are insufficient
for a *liberatory* postmodern science: they liberate human beings
from the tyranny of 'absolute truth' and 'objective reality', but
not necessarily from the tyranny of other human beings. In Andrew
Ross' words, we need a science 'that will be publicly answerable
and of some service to progressive interests.'" -- A.D.S.
 
S

santosh

Nomen said:
Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}

Thank you for fixing my program! Also please do not tell
anyone the password, it is copywrited.

What a lame troll attempt.

<snip>
 
R

Richard Heathfield

Nomen Nescio said:
Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}

The problem here is that you're using = for assignment. Try := instead, and
you should find that it works just fine. Don't forget to check the "MFC
Support" box in your gcc Makefile before invoking your JCL.
Thank you for fixing my program! Also please do not tell
anyone the password, it is copywrited.

Your secret is safe with me, I promise.
 
R

Roger Dodger

santosh said:
Nomen said:
Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}

Thank you for fixing my program! Also please do not tell
anyone the password, it is copywrited.

What a lame troll attempt.

<snip>

Oh, now, now.
I'm sure your mother used to tell you
that if you can't say anything nice,
just keep your fucking mouth shut, dumbass.
Am I right, or what?
 
R

rossum

Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
You need to hide your password here. Better to use:
if ((password + 1) != "november14") {
 
J

Joachim Schmitz

Roger said:
santosh said:
Nomen said:
Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}

Thank you for fixing my program! Also please do not tell
anyone the password, it is copywrited.

What a lame troll attempt.

<snip>

Oh, now, now.
I'm sure your mother used to tell you
that if you can't say anything nice,
just keep your fucking mouth shut, dumbass.
How about taking yout own advice?

PLONK
 
S

santosh

Roger said:
santosh said:
Nomen said:
Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}

Thank you for fixing my program! Also please do not tell
anyone the password, it is copywrited.

What a lame troll attempt.

<snip>

<snip even lamer expletives>

Is that the best you can do little troll? :) You leave the trolling to
Kenny and disappear back to where you emerged from. At least he has
*some* humour and sarcasm.
 
R

Roger Dodger

Joachim said:
How about taking yout own advice?

PLONK

Hey go **** yourself dickhead.
I wasn't even talking to you.
And you misspelled 'your',
you illiterate little bugfucker.
Eat shit and die.
 
R

Roger Dodger

santosh said:
Roger said:
santosh said:
Nomen Nescio wrote:

Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}

Thank you for fixing my program! Also please do not tell
anyone the password, it is copywrited.
What a lame troll attempt.

<snip>

<snip even lamer expletives>

Is that the best you can do little troll? :) You leave the trolling to
Kenny and disappear back to where you emerged from. At least he has
*some* humour and sarcasm.

You talk real big when you're invisible.
I *know* you wouldn't talk like that if we were face to face.
And as long as we both know that,
you can say whatever the **** you want to say.
 
R

Richard Heathfield

Roger Dodger said:

You talk real big when you're invisible.

Given that your email address is for a domain - brooklyn.ny - that doesn't
exist, you're being hypocritical. Although santosh uses a gmail address,
it is at least a valid address[1]. What's more, santosh contributes
constructively to this group, and you don't. Why not fix that, by helping
out with people's C questions? Or shall we just add you to the list of
snide, parasitic morons in our killfiles?

[1] Yes, I know my own address headers are invalid, but my sig contains
instructions for building my address that no bright person will have any
difficulty in following (which hasn't stopped it foxing a few non-bright
people).
 
R

Roger Dodger

Richard said:
Roger Dodger said:

You talk real big when you're invisible.

Given that your email address is for a domain - brooklyn.ny - that doesn't
exist, you're being hypocritical. Although santosh uses a gmail address,
it is at least a valid address[1]. What's more, santosh contributes
constructively to this group, and you don't. Why not fix that, by helping
out with people's C questions? Or shall we just add you to the list of
snide, parasitic morons in our killfiles?

[1] Yes, I know my own address headers are invalid, but my sig contains
instructions for building my address that no bright person will have any
difficulty in following (which hasn't stopped it foxing a few non-bright
people).

You're right, Mr. Heathfield, I should contribute to the group. And I
would have if you hadn't already beat me to it. I've learned a lot about
the C language and C programming over the years from reading your very
instructive posts.

But email addresses hasn't got a thing to do with being "invisible". I
would still be invisible even if I were using the right email address.

But that's neither here nor there
 
Z

Zom-B

Comparing strings with == or != is the same as comparing the memory
locations where both strings are stored, which are of course
different. Try strcmp(password, "november13") instead. Note that this
needs the include "#include <string.h>".

Moreover, it is always a bad idea to store the password as plain text
in the source code. Anyone obtaining a copy of either the source or
executable can see the password with minimal effort. In fact, this is
exactly how I once "cracked" the trial version of UniVBE when I was a
kid.
 
B

borkhuis

Moreover, it is always a bad idea to store the password as plain text
in the source code. Anyone obtaining a copy of either the source or
executable can see the password with minimal effort. In fact, this is
exactly how I once "cracked" the trial version of UniVBE when I was a
kid.

You know that this is illegal. Now we have to report you to the FBI,
the CIA, MI5 and the Internet Security Counsel. Please don't leave
your current location, you will be picked up within an hour.
 
M

Mark Wooding

Nomen Nescio said:
if (password != "november13") {

It's probably worth pointing out that you can improve security by
hashing the passwords. You should probably replace the above with
something like

if (strcmp(sha384(password), sha384("november13"))) { ... }

-- [mdw]
 
B

Bartc

Nomen Nescio said:
Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}


Try this:

#include <stdio.h>
#include <string.h>

int main(void) {
char password[40];
char beep[2]={7,0};
int i;

fflush(stdin);
fgets(password,40,stdin);
for (i=0; i<40; ++i) if (password<' '){password=0; break;};

if (strcmp(password,"november13")!=0) {
ten:
puts("INVALID PASSWORD");
printf(beep);
goto ten;
};
}
 
S

santosh

Bartc said:
Nomen Nescio said:
Hello, for an assignment I need to protect my files with a
password. Can anyone please tell me why my C/C++ program is
not working?!!

void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}


Try this:

#include <stdio.h>
#include <string.h>

int main(void) {
char password[40];
char beep[2]={7,0};
int i;

fflush(stdin);
fgets(password,40,stdin);
for (i=0; i<40; ++i) if (password<' '){password=0; break;};

if (strcmp(password,"november13")!=0) {
ten:
puts("INVALID PASSWORD");
printf(beep);


Instead of this I think it would be more portable to use the
standardised "bell" escape sequence.

printf("\b");

Also a fflush(stdout) for the invalid message above to actually appear.
 
R

Richard

Zom-B said:
Comparing strings with == or != is the same as comparing the memory
locations where both strings are stored, which are of course
different. Try strcmp(password, "november13") instead. Note that this
needs the include "#include <string.h>".

Moreover, it is always a bad idea to store the password as plain text
in the source code. Anyone obtaining a copy of either the source or
executable can see the password with minimal effort. In fact, this is
exactly how I once "cracked" the trial version of UniVBE when I was a
kid.

Wow. What a whoosh.
 
B

Bartc

santosh said:
Bartc wrote:
void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}

#include <stdio.h>
#include <string.h>

int main(void) {
char password[40];
char beep[2]={7,0};
int i;

fflush(stdin);
fgets(password,40,stdin);
for (i=0; i<40; ++i) if (password<' '){password=0; break;};

if (strcmp(password,"november13")!=0) {
ten:
puts("INVALID PASSWORD");
printf(beep);


Instead of this I think it would be more portable to use the
standardised "bell" escape sequence.

printf("\b");


I looked for \g in K&R2 but not mentioned. But doesn't mention \b either
except as backspace. Apparently \a is the bell.
Also a fflush(stdout) for the invalid message above to actually appear.

Wouldn't all those newlines in puts() force some output eventually? There
are an infinite number of messages so a few missing should do no harm.
 
B

Bartc

Mark said:
It's probably worth pointing out that you can improve security by
hashing the passwords. You should probably replace the above with
something like

if (strcmp(sha384(password), sha384("november13"))) { ... }

Wouldn't "november13" still exist in the executable? Unless sha384 is some
clever macro?

Perhaps encrypted in a separate program and the result put in here.
 
S

santosh

Bartc said:
santosh said:
Bartc wrote:
void main() {
char password[40];
fflush(stdin);
password = gets(NULL);
if (password != "november13") {
10 PRINT "INVALID PASSWORD"
20 BEEP
30 GOTO 10
}
}

#include <stdio.h>
#include <string.h>

int main(void) {
char password[40];
char beep[2]={7,0};
int i;

fflush(stdin);
fgets(password,40,stdin);
for (i=0; i<40; ++i) if (password<' '){password=0;
break;};

if (strcmp(password,"november13")!=0) {
ten:
puts("INVALID PASSWORD");
printf(beep);


Instead of this I think it would be more portable to use the
standardised "bell" escape sequence.

printf("\b");


I looked for \g in K&R2 but not mentioned. But doesn't mention \b
either except as backspace. Apparently \a is the bell.


Yes my mistake. '\a' is the sequence for audible alert.
Wouldn't all those newlines in puts() force some output eventually?
There are an infinite number of messages so a few missing should do no
harm.

Oh right. I read that puts as printf :)

Not a very good day I'm afraid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top