Fix my program

Discussion in 'C Programming' started by Nomen Nescio, Mar 5, 2008.

  1. Nomen Nescio

    Nomen Nescio Guest

    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.
     
    Nomen Nescio, Mar 5, 2008
    #1
    1. Advertising

  2. Nomen Nescio

    santosh Guest

    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>
     
    santosh, Mar 5, 2008
    #2
    1. Advertising

  3. 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.

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Mar 5, 2008
    #3
  4. Nomen Nescio

    Roger Dodger Guest

    santosh wrote:
    > 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>
    >


    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?
     
    Roger Dodger, Mar 5, 2008
    #4
  5. Nomen Nescio

    rossum Guest

    On Wed, 5 Mar 2008 09:20:15 +0100 (CET), 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") {

    You need to hide your password here. Better to use:
    if ((password + 1) != "november14") {

    > 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.
     
    rossum, Mar 5, 2008
    #5
  6. Roger Dodger wrote:
    > santosh wrote:
    >> 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>
    >>

    >
    > 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
     
    Joachim Schmitz, Mar 5, 2008
    #6
  7. Nomen Nescio

    santosh Guest

    Roger Dodger wrote:

    > santosh wrote:
    >> 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.
     
    santosh, Mar 5, 2008
    #7
  8. Nomen Nescio

    Roger Dodger Guest

    Joachim Schmitz wrote:

    >>>

    >> 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
    >
    >


    Hey go **** yourself dickhead.
    I wasn't even talking to you.
    And you misspelled 'your',
    you illiterate little bugfucker.
    Eat shit and die.
     
    Roger Dodger, Mar 5, 2008
    #8
  9. Nomen Nescio

    Roger Dodger Guest

    santosh wrote:
    > Roger Dodger wrote:
    >
    >> santosh wrote:
    >>> 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.
     
    Roger Dodger, Mar 5, 2008
    #9
  10. Roger Dodger said:

    <snip>

    > 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).

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Mar 5, 2008
    #10
  11. Nomen Nescio

    Roger Dodger Guest

    Richard Heathfield wrote:
    > Roger Dodger said:
    >
    > <snip>
    >
    >> 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
     
    Roger Dodger, Mar 5, 2008
    #11
  12. Nomen Nescio

    Zom-B Guest

    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.
     
    Zom-B, Mar 5, 2008
    #12
  13. Nomen Nescio

    Guest

    On Mar 5, 11:55 am, Zom-B <> wrote:
    > 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.
     
    , Mar 5, 2008
    #13
  14. Nomen Nescio

    Mark Wooding Guest

    Nomen Nescio <> wrote:

    > 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]
     
    Mark Wooding, Mar 5, 2008
    #14
  15. Nomen Nescio

    Bartc Guest

    "Nomen Nescio" <> wrote in message
    news:...
    > 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;
    };
    }


    --
    Bart
     
    Bartc, Mar 5, 2008
    #15
  16. Nomen Nescio

    santosh Guest

    Bartc wrote:

    >
    > "Nomen Nescio" <> wrote in message
    > news:...
    >> 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.

    > goto ten;
    > };
    > }
    >
    >
     
    santosh, Mar 5, 2008
    #16
  17. Nomen Nescio

    Richard Guest

    Zom-B <> writes:

    > 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.
     
    Richard, Mar 5, 2008
    #17
  18. Nomen Nescio

    Bartc Guest

    "santosh" <> wrote in message
    news:fqma5g$m4m$...
    > Bartc wrote:


    >> "Nomen Nescio" <> wrote in message
    >> news:...


    >>> 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.

    --
    Bart
     
    Bartc, Mar 5, 2008
    #18
  19. Nomen Nescio

    Bartc Guest

    Mark Wooding wrote:
    > Nomen Nescio <> wrote:
    >
    >> 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"))) { ... }


    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.

    --
    Bart
     
    Bartc, Mar 5, 2008
    #19
  20. Nomen Nescio

    santosh Guest

    Bartc wrote:

    >
    > "santosh" <> wrote in message
    > news:fqma5g$m4m$...
    >> Bartc wrote:

    >
    >>> "Nomen Nescio" <> wrote in message
    >>> news:...

    >
    >>>> 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.

    >> 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.


    Oh right. I read that puts as printf :)

    Not a very good day I'm afraid.
     
    santosh, Mar 5, 2008
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?anVubGlh?=
    Replies:
    2
    Views:
    593
    =?Utf-8?B?anVubGlh?=
    May 20, 2005
  2. Patrick Philippot
    Replies:
    0
    Views:
    490
    Patrick Philippot
    Apr 14, 2006
  3. Xah Lee
    Replies:
    22
    Views:
    1,184
    Tim Roberts
    Mar 21, 2006
  4. Xah Lee
    Replies:
    23
    Views:
    1,129
    Tim Roberts
    Mar 21, 2006
  5. Xah Lee
    Replies:
    21
    Views:
    849
    Tim Roberts
    Mar 21, 2006
Loading...

Share This Page