-
Notifications
You must be signed in to change notification settings - Fork 0
/
code003.erl
33 lines (26 loc) · 899 Bytes
/
code003.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
%% WAP which accepts a password from the user, stores the password in a file, and verifies it when the user enters it again
-module(password).
-export([run/0]).
run() ->
io:format("Enter password: ")
%% Read password from user
Password = read_password(),
%% Write password to file
file:write_file("password.txt", Password),
%% Verify password from user
case verify_password(read_password()) of
true ->
io:format("Password verified.~n");
false ->
io:format("Incorrect password.~n")
end.
read_password() ->
%% Read password from user
io:format("Enter password: "),
{ok, [Password]} = io:fread("","~s"),
Password.
verify_password(Expected) ->
%% Read password from file
{ok, [Actual]} = file:consult("password.txt"),
%% Compare passwords
Expected == Actual.