0

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.
2
Contributors
1
Reply
5
Views
7 Years
Discussion Span
Last Post by dlhale
0
Result := False;
    for i := 1 to Length(Password)-1 do
      begin
      if Password[i] = Password[i+1] then
        Exit;
      end;
    result := True;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.