program principal; const MAXINTENTO = 3; { máximo número de intentos } SEMILLADJB = 5381; { semilla para función de hash jdb2 } PASODJB = 33; { paso para función de hash jdb2 } NDJB = maxint; { cota de la función de hash } type Natural = QWord; { tipo de los naturales } { Procedimiento que escribe en la salida estándar el mensaje de intento fallido. Los parámetros son: - codigo: el código de hash de la contraseña ingresada - intento: el intento actual - intentos: el número máximo de intentos permitidos } procedure writeFallo(codigo : Natural; intento, intentos : integer); begin writeLn('Intento de login fallido (',intento:1,' de ',intentos:1,')'); writeLn('Hash: ', codigo:1) end; procedure readAndHashLn(semilla, paso, N : Natural; var codigo : Natural); var digito : char; begin read(digito); { Verifica si el primer dígito es un "." } codigo:= semilla; { Para trabajar con la semilla } If ord(digito) = ord('.') then writeln('La contraseña no puede comenzar con un ".".'); while ord(digito) <> ord('.') do begin codigo:= codigo * paso + ord(digito); read(digito); end; codigo:= codigo mod N; readln(); end; procedure login(codigo : Natural; intentos : integer; var ok : boolean); var intento:integer; codigo2:Natural; begin intento:= 0; ok:= false; while (ok = false) and (intento > 0) do begin readAndHashLn(SEMILLADJB, PASODJB, NDJB, codigo2); { Obtiene el hash de la contraseña ingresada } if codigo = codigo2 then ok:=true else begin writeFallo(codigo2, intento, intentos); intento:= intento+1; end; end end; var codigo : Natural; ok : boolean; begin { registro de usuario } writeLn('Registro de Usuario'); write('Ingrese su contraseña: '); readAndHashLn(SEMILLADJB, PASODJB, NDJB, codigo); writeLn('Hash: ', codigo:1); { login de usuario } writeLn('Login de Usuario'); writeLn('Ingrese su contraseña, tiene hasta ', MAXINTENTO:1, ' intentos.'); login(codigo, MAXINTENTO, ok); if ok then writeLn('Login realizado correctamente.') else writeLn('Fuera de aquí!') end.
Write, Run & Share Pascal code online using OneCompiler’s Pascal online compiler for free. It’s a straightforward, accessible way to learn and experiment with Pascal programming right from your browser. OneCompiler supports modern Pascal syntax and provides a ready-to-use editor for immediate execution.
Pascal is a procedural programming language developed in the 1970s by Niklaus Wirth. It was designed to encourage good programming practices and structured programming. Pascal is widely used in teaching computer science fundamentals and has influenced many modern languages.
The following is a simple Pascal program that prints a greeting:
program HelloWorld;
begin
writeln('Hello, OneCompiler!');
end.
OneCompiler’s Pascal editor supports stdin through the I/O tab. Here’s an example that reads a user's name and prints a greeting:
program GreetUser;
var
name: string;
begin
readln(name);
writeln('Hello, ', name, '!');
end.
var
age: integer;
name: string;
score: real;
flag: boolean;
Type | Description |
---|---|
integer | Whole numbers |
real | Floating-point numbers |
char | Single character |
string | Sequence of characters |
boolean | True or False |
if score >= 50 then
writeln('Pass')
else
writeln('Fail');
for i := 1 to 5 do
writeln(i);
i := 1;
while i <= 5 do
begin
writeln(i);
i := i + 1;
end;
i := 1;
repeat
writeln(i);
i := i + 1;
until i > 5;
procedure SayHello;
begin
writeln('Hello!');
end;
function Add(a, b: integer): integer;
begin
Add := a + b;
end;
This guide provides a quick reference to Pascal programming syntax and features. Start coding in Pascal using OneCompiler’s Pascal online compiler today!