Update of /cvsroot/tmda/tmda/contrib/cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv22995
Added Files:
Authenticate.py
Log Message:
Password testing code. See INSTALL for more details on how this works.
--- NEW FILE ---
#!/usr/bin/env python
#
# Copyright (C) 2002 Gre7g Luterman <[EMAIL PROTECTED]>
#
# This file is part of TMDA.
#
# TMDA is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of this license should
# be included in the file COPYING.
#
# TMDA 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. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with TMDA; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"Password checker for tmda-cgi."
import crypt
import os
import os.path
import pwd
import random
import string
def ComparePassword(Filename, User, Password):
"""Checks password against a given filename.
ComparePassword returns 1 if the password can be authenticated. It returns None
if it couldn't be."""
try:
F = open(Filename)
except:
return None
RetVal = None
while (1):
PasswordRecord = F.readline()
# End of file?
if PasswordRecord == "":
break
Temp = string.split(string.strip(PasswordRecord), ":")
# Have we found the correct user record?
if Temp[0] == User:
Perm = os.stat(Filename)[0] & 07777
# Is the password in the file encrypted?
if (Perm != 0400) and (Perm != 0600):
if crypt.crypt(Password, Temp[1][:2]) == Temp[1]: RetVal = 1
break
else:
if Temp[1] == Password: RetVal = 1
break
F.close()
return RetVal
def CheckPassword(Form):
"Checks a password against password files."
# Find the requested home directory
os.environ["HOME"] = pwd.getpwnam(Form["user"].value)[5]
RetVal = ComparePassword(os.path.expanduser("~/.tmda/tmda-cgi"), \
Form["user"].value, Form["password"].value)
if RetVal: return RetVal
return ComparePassword("/etc/tmda-cgirc", Form["user"].value, \
Form["password"].value)
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs