I need to write a program that asks a user for their new password, to check that they have entered it correctly they must verify it by entering it again. If the two passwords matach then you accept the change and tell the user that they have been successful on the first attempt and you print out the new password.

If they make a mistake entering the second password, the program tells them their password has not been changed and the program starts again. When they finally get it correct, the program tells them they have been successful and how many attepts it took them.

Please help me again.

Dani AI

Generated

wanted a Pascal program that asks for a new password, asks the user to retype it, repeats on a mismatch, and finally reports success and how many tries it took. has a solid loop-based reply that demonstrates the basic flow and will work for a classroom exercise.

A few practical improvements and cautions to keep in mind:

  • Do not print or store plaintext passwords in real software. Printing the new password to the console is fine for a learning exercise, but in any real system you should store only a salted hash (see the OWASP guidance linked below).
  • Prevent accidental mismatches: trim leading/trailing whitespace before comparing, and reject empty entries or enforce a minimum length. That avoids "I hit space by mistake" problems.
  • Improve input privacy and portability: console input normally echoes characters. For a masked password entry use a character-by-character read routine (for example ReadKey under Pascal consoles) or a platform-specific method; be aware console methods vary by compiler and OS. See the Free Pascal documentation for console units.
  • Decide clearly what an "attempt" means. Count each verification cycle (including the successful one) if you want "first attempt" to correspond to a counter value of 1. Consider adding an explicit max-attempt limit to avoid infinite retry loops.

For secure storage and handling of passwords, follow established practices rather than keeping plaintext: see the OWASP Password Storage Cheat Sheet for current best practices. For Pascal-specific console routines check the Free Pascal documentation for the CRT/console units.

{
I need to write a program that asks a user
for their new password, to check that they have entered
it correctly they must verify it by entering it again.
If the two passwords matach then you accept the change
and tell the user that they have been successful on the first
attempt and you print out the new password.
If they make a mistake entering the second password,
the program tells them their password has not been changed
and the program starts again. When they finally get it correct,
the program tells them they have been successful
and how many attepts it took them.
}

Program Program01;

Uses Crt;

Var Password,NewPassword,VerifyPassword:String;
    Counter:Integer;
    Result:Boolean;{true or false}
Begin {main}
     Counter:=0;
     Password:='123-Fla-ming-Claw-456';{just example}
     Result:=False;{why?}
     Repeat
        Write('Give me the new password: ');
        ReadLn(NewPassword);
        ClrScr;{clears the screen,part of Crt unit}
        Write('Repeat the new password: ');
        ReadLn(VerifyPassword);
        If (NewPassword <> VerifyPassword) Then
           Begin
              WriteLn('Error while verifying the  password!Try Again!');
              WriteLn('Your password is: ',Password);
              {'result' stays 'False'}
           End
        Else
           Begin
              Password:=NewPassword;  {changes values}
              Result:= True;       {got it?}
           End;
        Counter:=Counter+1;{add 1 each round}
     Until Result = True; {analizing here}
     WriteLn;
     WriteLn('New password accepted!!');
     WriteLn('Your new password is : ',Password);
     WriteLn('Total Trying: ',Counter);
     ReadLn;
End.

{
-= Note By FlamingClaw =-

All programs created by me are written and tested
in Dev Pascal and/or Turbo Pascal 7.0

-= Created By FlamingClaw =-
-=2009.03.26=-
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.