Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

c kiddies, need your help

Name: Anonymous 2010-04-25 18:53

int main(){
    char data[2][5] = {"root", "pass"};
    char holder[5];
    printf("Please enter your username>");
    gets(holder);
    if(data[1]==holder){
    printf("Correct Username");
    };
    return 0;
}

The problem is even if I type the correct username in it will not pass to
if(data[1]==holder){

Name: Anonymous 2010-04-25 18:57

str(n)cmp.

Name: >>2 2010-04-25 18:58

Did I also mention that there's so many security vulnerabilities in that that... ah whatever, not like anyone would be stupid enough to use something like that for actual "security"

Name: Anonymous 2010-04-25 18:59

>>1
To compare strings, use strcmp(s1, s2). This function will return zero if the two strings are identical.
Also, using gets() and fixed-size string buffers is a great way of making ENTERPRISE-QUALITY VULNERABILITIES.

Name: Anonymous 2010-04-25 18:59

I know this fails for security, but it is what my teacher wants.

Name: Anonymous 2010-04-25 19:00

>>5
Murder her.

Name: Anonymous 2010-04-25 19:33

#include <stdio.h>
int main(void)
{ char data[2][5] = {"root", "pass"},
       *holder = NULL;
  size_t n;
  ssize_t r;
  fputs("Please enter your username>", stdout);
  fflush(stdout);
  r = getline(&holder, &n, stdin);
  holder[r - 1] = 0;
  if(!strcmp(data[1], holder))
    puts("Correct Username");
  return 0; }

Name: Anonymous 2010-04-25 19:34

>>7
forgot #include <string.h>

Name: Anonymous 2010-04-25 19:39

>>7
Getting these errors
/out:hw9.exe
hw9.obj
hw9.obj : error LNK2019: unresolved external symbol _getline referenced in funct
ion _main
hw9.exe : fatal error LNK1120: 1 unresolved externals

Name: Anonymous 2010-04-25 19:42

>>1,9
[code] tags.

Name: Anonymous 2010-04-25 20:17

Even if fix all the vulnerabilities in your example, it's still a terribad idea.

1) You seem to be building this on Windows, so you're going to give this exe to someone to run right? He can just use a disassembler, or in this case (since there's no encryption), he could just run a "strings" on it or whatever.
2) If this was meant as some sort of remote-auth. I've once encountered such sillyness in a *nix environment where the permissions were +x only (no r/w). a bit of minimal gdb magic and the password presented itself.
The only way this can work is if it's fully remote and the user has no way on accessing the local file.

tl;dr: terrible idea.

Name: Anonymous 2010-04-25 20:19

>>11 see >>5 (and possibly >>6)

Name: Anonymous 2010-04-25 20:20

store the password as a hash/digest that's hard to reverse

Name: Anonymous 2010-04-25 20:22

My assignment is just to store it in a 2D array, and then check to see if it is correct. Nothing I try seems to work though.

Name: Anonymous 2010-04-25 20:26

>>14
Walk the array, comparing every username with the one provided. If they are equal, compare the password associated with that username with the provided password. If they are equal, yay, otherwise, noes. Make the last array entry { NULL, NULL } so you can stop on the last username by checking whether it is null.

Name: Anonymous 2010-04-25 20:57

[quote]Using == for string comparison[/quote]

Name: Anonymous 2010-04-25 21:06

Name: Anonymous 2010-04-26 1:19

This is the last time I reply to a thread without proper use of code tags in OP.

Don't change these.
Name: Email:
Entire Thread Thread List