954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pascal Program - please help!

I am trying to create a program that when you enter a word which has a repeated pattern of letters immediately next to one another will reject the password, but otherwise accept it.

E.g.
London, kiwi, a and onion would all be accepted
but
Papa, aa, apple and banana would all be rejected.

At the moment my code (shown below) for some reason ALSO rejects passwords such as London, onion and kiwi, I think simply because they have a letter or word pattern repeated in the word.

Could you look at the code below and possibly tell me how to adjust it or why it is doing what it is doing?

(I am using Lazarus, with the Free Pascal language)

Thanks

program BIO2000PassWord;

uses
  SysUtils, StrUtils, crt
  { you can add units after this };

var
  lengthpw, reject : integer;
  password : string;

Procedure split (pw : string; l : integer);
var c1,c2, c3, c4 : integer;
begin
  for c1 := 1 to l do
  begin
   for c2 := c1 to l do
    begin
     for c3 := (c2 + 1) to (l + 1) do
     begin
      c4 := c3 + (c2 - c1);
      if (pw[c1..c2]=pw[c3..c4]) then
       begin
        writeln;
        writeln ('Rejected');
        reject := 1;
        readln;
        exit;
       end
     end;
    end;
   end;
end;

begin
  Write ('Please enter a password: ');
  Read (password);
  password := UpperCase (password);
  lengthpw := length(password);
  lengthpw := lengthpw + (lengthpw div 2);
  split (password, lengthpw);
  if reject <> 1 then
  begin
  writeln ('Accepted');
  end;
  readln;
end.
ecklcakes
Newbie Poster
19 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 
Result := False;
    for i := 1 to Length(Password)-1 do
      begin
      if Password[i] = Password[i+1] then
        Exit;
      end;
    result := True;
dlhale
Newbie Poster
10 posts since Nov 2008
Reputation Points: 12
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: