473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Password challenge

8
C++ Code:
Help!!! Problem:

>>goto Password 1:

Enter pw1 & pw2
-Program only evaluates first character
-How can I evaluate all characters entered!!
-If first letter same >> "Good Match"
-If all char's are the same >> "Passwords don't match, Try Again"

What is the Answer to evaluating all characters @ one time?????


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

main()
{

char name[30];
int n;
int r;
char a;
int q;
char pw1;
char pw2;

printf ("What is your name?");
scanf ("%s", &name);
printf ("High (%s)\n\n", name);
printf ("Is this correct?");
scanf ("%s", &a);
if ((a == 'y') || (a == 'Y'))
goto PASS_WORD1;
else
goto NAME_1;

NAME_1:
printf ("Please Re-enter name!");
scanf("%s",&name);
printf ("Okay, %s\n\n", &name);
goto PASS_WORD1;

PASS_WORD1:

printf ("Please enter a password to feed your data into the system!!\n",&pw1);
scanf ("%s", &pw1);
printf ("Please Enter same password again for security reasons\n",&pw2);
scanf ("%s", &pw2);
if (pw1 == pw2)
{printf ("Good match, (%S) ...\n", &name);
goto QUESTION_1;}
else
{ printf ("Passwords don't match, Try again (%s) @@@\n", &name);
goto PASS_WORD2;

PASS_WORD2:
printf ("Please enter a password to feed your data into the system!!\n",&pw1);
scanf ("%s", &pw1);
printf ("Please Enter same password again for security reasons\n",&pw2);
scanf ("%s", &pw2);
if (pw1 != pw2)
{ printf ("Passwords don't match, consider remembering in your head\n");}
goto END_NOTEST;


QUESTION_1:
printf ("Please enter the Number of Questions you would like between (1-50) ?\n");
scanf ("%s", &q);

if ((q >= '1') && (q <= '50'))
{ printf ("Get Ready,(%s), !!!!!!\n",&name);
goto START_TEST;}

else
{ printf ("Invalid Entry, Try Again!!\n");
scanf ("%s", &q);}
if ((q >= '1') && (q <= '50'))
{ printf ("Finally, (%s), it took you long enough,!!!\n", &name);
goto START_TEST;}

else
{ goto END_NOTEST;

return 0;

START_TEST:

printf ("\nWelcome to the First Multiple Choice Test\n");
printf ("Created by Jonathan J. Soard, Oct 06");

END_NOTEST:
printf ("Bye Bye (%s), Better Luck next time\n", &name);
return 0;}
}
}
Oct 25 '06 #1
5 3181
Banfa
9,065 Expert Mod 8TB
To start with if you want to store a password of more than 1 character then you should declare pw1 and pw2 as having more than 1 character, you need to declare arrays. Has you currently have it if the user enters passwords of more than 1 character you write to unallocated memory and invoke undefined behaviour.

Also in modern program using goto is usually frowned upon, I think it would be especially frowned upon in the way you have used it since a lot of them are completely unrequired if you made proper use of code blocks after if statements.

Finally if you want to compare 2 string use the function

int strcmp ( const char * string1, const char * string2 );

declared in string.h
Oct 25 '06 #2
chiefs
8
To start with if you want to store a password of more than 1 character then you should declare pw1 and pw2 as having more than 1 character, you need to declare arrays. Has you currently have it if the user enters passwords of more than 1 character you write to unallocated memory and invoke undefined behaviour.

Also in modern program using goto is usually frowned upon, I think it would be especially frowned upon in the way you have used it since a lot of them are completely unrequired if you made proper use of code blocks after if statements.

Finally if you want to compare 2 string use the function

int strcmp ( const char * string1, const char * string2 );

declared in string.h
I'm new to the Programming arena, please elaborate on what you mean by declaring the char in array and allocating more space for the char's to be read.

Do you mean by declaring the char in an array like this

char pw1[8];
char pw2[8];

How about allocating enough space for the char's, what would be the line coding for this?
Oct 26 '06 #3
chiefs
8
I'm only trying to get a result that is True with correct Input!!

With these statements, after Confirm>>Comes back Good even if put different characters. If I make the If statement: if (pw1 == pw2)
Answer always comes back "No Good".
What would you suggest to fix the Incorrect Response?????

Possibly- add an algorithm to test each character and space it should work.
- loop with counter to test each character entered (Verify in reverse
order if correct sequence for both pw1 & pw2 Valid

After this, I plan on working on storing the name and password in a excel file with the password encrypted (Algorithm) then work on the question, scores, average, so fourth & so on!!

Right now I'm at 50/50

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

main()
{

char pw1[8];
char pw2[8];

PASS_WORD1:
printf ("Enter your 8 character password\n");
scanf ("%s", &pw1);
printf ("Confirm!!\n ");
scanf ("%s", &pw2);
if (pw1 != pw2)
{printf("Good");
goto QUESTION_1;}
else
{printf("No Good");
goto PASS_WORD1;}

QUESTION_1:

}
Oct 27 '06 #4
arne
315 Expert 100+
I'm only trying to get a result that is True with correct Input!!

With these statements, after Confirm>>Comes back Good even if put different characters. If I make the If statement: if (pw1 == pw2)
Answer always comes back "No Good".
What would you suggest to fix the Incorrect Response?????

Possibly- add an algorithm to test each character and space it should work.
- loop with counter to test each character entered (Verify in reverse
order if correct sequence for both pw1 & pw2 Valid

After this, I plan on working on storing the name and password in a excel file with the password encrypted (Algorithm) then work on the question, scores, average, so fourth & so on!!

Right now I'm at 50/50
Try
Expand|Select|Wrap|Line Numbers
  1. if( strcmp(pw1, pw2) == 0 )
  2.  
instead of your if statement (your code doesn't compare the strings, but the addresses).
Oct 27 '06 #5
Banfa
9,065 Expert Mod 8TB
Please don't double post.
Oct 27 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Obi-Too | last post by:
I need to validate a password to only allow A-Z, a-z and 0-9. I thought this would work: function Validate() { var passphrase = document.all.challenge.value; var re = //; if...
1
by: twhan twhan via .NET 247 | last post by:
Hi, currently i am developing a Radius server application. Cananyone show me how can i unpack the "User-Password" attribute sothat i can get back the password in plain text so that i canverify it...
7
by: jrefactors | last post by:
I want to ask how password is stored and how to check the authentication? I have heard password is never encrypted and decrypted, but it is hashed. For example, consider a simple email logon...
36
by: dcrespo | last post by:
Hi all, I have a program that serves client programs. The server has a login password, which has to be used by each client for logging in. So, when the client connects, it sends a string with a...
26
by: David Garamond | last post by:
I read that the password hash in pg_shadow is salted with username. Is this still the case? If so, since probably 99% of all PostgreSQL has "postgres" as the superuser name, wouldn't it be better...
0
by: richard | last post by:
The date for the second PyWeek challenge has been set: Sunday 26th March to Sunday 2nd April (00:00UTC to 00:00UTC). The PyWeek challenge invites entrants to write a game in one week from...
6
by: Frank L | last post by:
I have some accounting and tax receipting type applications, developed for charitable and non profit groups, that are exhibiting strange behaviour on a few of the 30 or 40 user machines. When...
22
by: teejayem | last post by:
Hi, I am new to programming with databases and was wanting some help. Is there any way to password protect an access database and access sent sql commands to it via vb.net code? Any help...
4
by: Steve | last post by:
Hi guys, You know how annoying it is when Visual Studio keeps asking you for a username and password to access TFS? I figured it would be easy to write a little System Tray utility that could...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.