5 Replies - 8511 Views - Last Post: 27 September 2007 - 04:16 AM Rate Topic: -----

#1 mac612  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-September 07

User ID and Password Validation

Posted 27 September 2007 - 01:06 AM

HI. I need help on the coding below. How to change the User ID part into entering just one line instead of entering one number and an enter after each? How to control the password part where it can repeat the question if a person enter his person incorrectly for example if it contains any alphabet because both field (User ID and Password) can only contain digits. 7 and 8 respectively. Please help... Your kind attention is most appreciated!

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

void main(){
	int a,b,c,d,e,f,g,h;



	cout<<"Welcome to registeration"<<endl;
	cout<<"Please choose your user ID by enter 8 digit"<<endl;
	cin>>a>>b>>c>>d>>e>>f>>g>>h;

	while((a>9)||(b>9)||(c>9)||(d>9)||(e>9)||(f>9)||(g>9)||(h>9)){
		cout<<"Invalid user ID,please choose 8 digit:"<<endl;
		cin>>a>>b>>c>>d>>e>>f>>g>>h;
	}
	cout<<"Your ID is "<<a<<b<<c<<d<<e<<f<<g<<h<<endl;
	cout<<"ID received"<<endl;
	cout<<"Please key in your password in 7 digit"<<endl;

	char password[7]="",tmp='a';
	int i=0;
	while(tmp!=7)
	{
		while(!kbhit());
		tmp=getch();
		if(tmp!=7)
		{
			printf("*");
			password[i++]=tmp;
		}
		if(i>7){
			printf("\nYour Password:%s\n",password);
		}
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: User ID and Password Validation

#2 jjhaag  Icon User is offline

  • me editor am smartastic
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,789
  • Joined: 18-September 07

Re: User ID and Password Validation

Posted 27 September 2007 - 01:26 AM

this is very similar to source code that you've posted previously...you may want to just continue the already existing thread.

is there a reason that you can't store the ID's and PW's as characters? the previous code using char arrays appeared to work well for your purposes.

-jjh
Was This Post Helpful? 0
  • +
  • -

#3 mac612  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-September 07

Re: User ID and Password Validation

Posted 27 September 2007 - 02:06 AM

View Postjjhaag, on 27 Sep, 2007 - 01:26 AM, said:

this is very similar to source code that you've posted previously...you may want to just continue the already existing thread.

is there a reason that you can't store the ID's and PW's as characters? the previous code using char arrays appeared to work well for your purposes.

-jjh



I know but my partner said that the lecturer want it this way's style... That's why I changed... Any ideas in improvements please? Thanks a lot jjh.
Was This Post Helpful? 0
  • +
  • -

#4 jjhaag  Icon User is offline

  • me editor am smartastic
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,789
  • Joined: 18-September 07

Re: User ID and Password Validation

Posted 27 September 2007 - 03:00 AM

what exactly is the requirement? that each digit is stored in a separate integer variable, or that each separate variable must be read directly from the input stream as an integer?

In the former case, you could still store the input in a char[], but then convert each element to an int and store it in the appropriate variable. In the latter, I'm not aware of a way to do it. I've seen a couple other similar problems, and all have been addressed with the char[] solution.

-jjh

This post has been edited by jjhaag: 27 September 2007 - 03:00 AM

Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,070
  • Joined: 10-May 07

Re: User ID and Password Validation

Posted 27 September 2007 - 04:03 AM

You can use atoi -> atoi or sprintf to convert char to int.
Was This Post Helpful? 0
  • +
  • -

#6 mac612  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-September 07

Re: User ID and Password Validation

Posted 27 September 2007 - 04:16 AM

View Postjjhaag, on 27 Sep, 2007 - 03:00 AM, said:

what exactly is the requirement? that each digit is stored in a separate integer variable, or that each separate variable must be read directly from the input stream as an integer?

In the former case, you could still store the input in a char[], but then convert each element to an int and store it in the appropriate variable. In the latter, I'm not aware of a way to do it. I've seen a couple other similar problems, and all have been addressed with the char[] solution.

-jjh


Is each seperate variable is read directly as an integer or character so that it could be stored and viewed on the next login of different user's with predefined accounts. But I guess the validation method is flawless in the looping statement which you've adviced earlier but the problem is storing the whole thing in a file only.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1