ONO::ToolBox::Auth::Login

package ONO::ToolBox::Auth::Login;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################


use strict;

use ONO::IO;
use ONO::Lib::Data::Crypt;
use ONO::Lib::Code::RandomID;

###############################################################################
# ONO
###############################################################################

sub login {

#: This *may* be DEPRECATED, based on ONO::ToolBox::Auth status.

my ($self,$username,$password) = @_;
my $sid;
my $status = "bad username or password";

$username = lc $username;
$username =~ s~[^a-z0-9]~~g;

if ($username && $password) {

foreach my $shadow (ONO::IO->list("etc/shadow")) {

my @sp = split(/:/,$shadow);

if ($sp[0] eq $username && ONO::Lib::Data::Crypt->pwdchk($password,$sp[1])) {

my @passwds = ONO::IO->list("etc/passwd");

foreach my $passwd (@passwds) {

my @pd = split(/:/,$passwd);
if ($pd[0] eq $username) {

$sid = ONO::Lib::Code::RandomID->make(64);
$passwd =~ s/\n//g;
$status = "";

ONO::IO->mkpath("var/sessions");
ONO::IO->store("var/sessions/$sid.sid","$passwd");
ONO::IO->store("var/sessions/$sid\_wd.txt","$pd[5]");
}
}
}
}
}

return ($status,$sid);

}

###############################################################################
# end of script
###############################################################################

1;

__END__