def changePasswd(request):
	if isStudent(request):
		return render_to_response('student/changePasswd.html', {'Err' : ''})
	elif isSecretary(request):
		return render_to_response('secretary/changePasswd.html', {'Err' : ''})
	elif isWardenOffice(request):
		return render_to_response('wardenOffice/changePasswd.html', {'Err' : ''})
	elif isWarden(request):
		return render_to_response('warden/changePasswd.html', {'Err' : ''})
	else:
		return redirect ('/crs/')
def resetPasswd(request):
	address = ""
	if isStudent(request):
		address = "student"
	elif isSecretary(request):
		address = "secretary"
	elif isWardenOffice(request):
		address = "wardenOffice"
	elif isWarden(request):
		address = "warden"
	else:
		return redirect ('/crs/')

	uid = request.session.get("uid")
	oldPasswd = request.POST.get('oldPasswd','')
	newPasswd = request.POST.get('newPasswd1','')
	newPasswd2 = request.POST.get('newPasswd2','')
	if validatePassword(oldPasswd) or validatePassword(newPasswd) or validatePassword(newPasswd2):
		return render_to_response(address + '/changePasswd.html', {'Err':'Password length must be between 8 & 20'})

	hash_object = hashlib.sha256(b""+oldPasswd)
	oldPasswd = hash_object.hexdigest()
	hash_object = hashlib.sha256(b""+newPasswd)
	newPasswd = hash_object.hexdigest()

	hash_object = hashlib.sha256(b""+newPasswd2)
	newPasswd2 = hash_object.hexdigest()

	if newPasswd != newPasswd2 :
		return render_to_response(address + '/changePasswd.html', {'Err' : 'Password mismatch in New Password'})
	
	if(request.session.get("user_type") == 	"student" or request.session.get("user_type") == "secretary"):
		try:
			obj = Student.objects.get(uid=uid,password=oldPasswd)
			obj.password = newPasswd
			obj.save()
		except:
			return render_to_response(address + '/changePasswd.html', {'Err' : 'old Password is Wrong!'})
	else:
		try:
			obj = Faculty.objects.get(uid=uid,password=oldPasswd)
			obj.password = newPasswd
			obj.save()
		except:
			return render_to_response(address + '/changePasswd.html', {'Err' : 'old Password is Wrong!'})
	return render_to_response('login/loginPage.html', {'Err' : 'Password changed successfully'})