2 # Copyright 2011 Paul Haensch
3 # This file is part of Busy
5 # Busy is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Busy is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Busy. If not, see <http://www.gnu.org/licenses/>.
20 user="$(echo -E "$_POST[\"user\"]" |sed -rn '1{/^[a-zA-Z0-9_+@.-]+$/p}')"
21 pass="$_POST[\"pass\"]"
22 userfile="$_DATA/auth/user$(echo -E "$user" |sha1sum |cut -c1-40)"
24 if [ -r "$userfile" ]; then
25 salt=$(sed -nr 's:^salt=(.+)$:\1:p' "$userfile")
26 ssum=$(sed -nr 's:^auth=(.+)$:\1:p' "$userfile")
27 rsum=$(echo -E "$salt$pass" |sha1sum |cut -c1-40)
29 if [ "$ssum" = "$rsum" ]; then
30 sid="$(apg -n1 -a1 -m32 -x32 -M CLN)"
31 sessionfile="$_DATA/auth/session$sid"
32 echo -E "$user $(($(date +%s) + 1800))" >"$sessionfile"
33 echo -E "Location: $HTTP_REFERER"
34 echo -E "Set-Cookie: session=$sid; HttpOnly"
36 echo -E "Location: $HTTP_REFERER"