/* */

PDA

View Full Version : C++



Cabdullahi
04-23-2009, 09:42 PM
Anybody here good at c++...ive designed a password function but its kinda useless....it doesnt compare it with the a set password....basically im kinda wack at this maybe some1 could help me :)

here's the code

// hndfh.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

// 00000.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

int main ()
{
cout << "Enter you password: (max 4 characters)" << endl;
// password (char array, doesn't work as string)
char password[25];

int i = 0; // used to index the current character being read
while (true) // infinite loop, broken by pressing return
{
password[i] = getch(); // get the current character
cout << "*"; // output a star (can be replaced with a different character)

if (GetAsyncKeyState(VK_RETURN)) // if return has been pressed
break; // break from the loop

i++; // increment our index
}

// now fill the rest of the array with '\0' (NULL) character
for (i; i < strlen(password); i++)
password[i] = '\0';

// output the password (just for testing)
cout << endl << "Welcome Ahmed Ali";

// end of the program
cout << endl << "Press any key to continue . . .";
getch ();
}
Reply

Login/Register to hide ads. Scroll down for more posts
AabiruSabeel
04-23-2009, 10:05 PM
:sl:

You are not comparing it with a stored password. And you are not displaying the pwd where you say:
// output the password (just for testing)
cout << endl << "Welcome Ahmed Ali";
If you are testing it, then there should be a <<password also in that statement.

Another point that I noticed:
// now fill the rest of the array with '\0' (NULL) character
for (i; i < strlen(password); i++)
password[i] = '\0';
There is no need for the loop here, since you are not changing the value of the index i after entering the password in the previous loop. And since it was counting the no. of chars entered, it will be pointing at the end of the password already. You can simply write password[i] = '\0'; and it will close the string. Try it.

Don't you think this thread should be in the Educational Issues section?

Its late night here. If there are other queries, I will try to check tomorrow inshaAllah.

:w:
Reply

Forced_In
04-23-2009, 10:34 PM
format_quote Originally Posted by Abdullahii
Anybody here good at c++...ive designed a password function but its kinda useless....it doesnt compare it with the a set password....basically im kinda wack at this maybe some1 could help me :)

here's the code

// hndfh.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

// 00000.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

int main ()
{
cout << "Enter you password: (max 4 characters)" << endl;
// password (char array, doesn't work as string)
char password[25];

int i = 0; // used to index the current character being read
while (true) // infinite loop, broken by pressing return
{
password[i] = getch(); // get the current character
cout << "*"; // output a star (can be replaced with a different character)

if (GetAsyncKeyState(VK_RETURN)) // if return has been pressed
break; // break from the loop

i++; // increment our index
}

// now fill the rest of the array with '\0' (NULL) character
for (i; i < strlen(password); i++)
password[i] = '\0';

// output the password (just for testing)
cout << endl << "Welcome Ahmed Ali";

// end of the program
cout << endl << "Press any key to continue . . .";
getch ();
}
assalam

Have you considered joining a usenet group like "comp.lang.c++" ? I think you will learn a lot there abot cpp.

wassalam
Reply

Cabdullahi
04-23-2009, 11:25 PM
haha the starting thread was a big joke ...i fooled you guys this is my password function

// ff.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

#include <string>
#include <iostream>
using std::string;
using std::cin;
using std::cout;

int main(){
string a;
cin>>a;
if(a == "1234"){

cout<<"Welcom Mr Ahmed Ali \n";
}
else if (a != "1234"){
cout << "incorrect password, please try again.";
}
system("PAUSE");
return 0;
}
Reply

Welcome, Guest!
Hey there! Looks like you're enjoying the discussion, but you're not signed up for an account.

When you create an account, you can participate in the discussions and share your thoughts. You also get notifications, here and via email, whenever new posts are made. And you can like posts and make new friends.
Sign Up
convert
04-24-2009, 03:01 AM
Should probably be using hashes for password stuff.
Reply

AabiruSabeel
04-24-2009, 03:45 AM
:sl:

Both are two different methods of coding. In the first one, you are simply entering the pwd and then displaying it. If you want to check it with a stored pwd, then you will have to learn file handling as well.

In your second program, you have hardcoded the password, and you are not using asterisk to mask it while entering. Hardcoded pwds cannot be changed, therefore not user-friendly. Its better to use hashes, and store the pwds in a file, and use it for login.

what does the strlen function return?
strlen() returns the length of the string in int. You will have to include string.h header file for it.
Reply

AabiruSabeel
04-24-2009, 11:41 AM
^yes it takes a string, and returns the number of characters in it.
The declaration syntax in string.h is:
Code:
size_t strlen(const char *s);
Reply

Yanal
04-25-2009, 03:19 AM
I thought you needed help with grades because you got C+,but it's not about that. All this computer stuff is hard....
Reply

Hey there! Looks like you're enjoying the discussion, but you're not signed up for an account.

When you create an account, you can participate in the discussions and share your thoughts. You also get notifications, here and via email, whenever new posts are made. And you can like posts and make new friends.
Sign Up
British Wholesales - Certified Wholesale Linen & Towels | Holiday in the Maldives

IslamicBoard

Experience a richer experience on our mobile app!