summaryrefslogtreecommitdiff
path: root/GradeBook_lib.tcl
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2011-01-26 11:42:30 -0500
committerEugeniy Mikhailov <evgmik@gmail.com>2011-01-26 11:42:30 -0500
commite268645a36a0d2ef3d485b4d36391b9e80db4f65 (patch)
tree9a4df9e97f5cf5d037d84e9c865c960f4e25a62a /GradeBook_lib.tcl
parent5ac82bbf41a2b6ffb394d1b4ed8db9a02b9ad5bd (diff)
downloadGradeBook-e268645a36a0d2ef3d485b4d36391b9e80db4f65.tar.gz
GradeBook-e268645a36a0d2ef3d485b4d36391b9e80db4f65.zip
added password reseting code
Ignore-this: 45d6ad050ef8806ae7cc85cde72a9954 darcs-hash:20110126164230-067c0-0542eb7dfb109d7261868971f555a4297b0a76d3.gz
Diffstat (limited to 'GradeBook_lib.tcl')
-rwxr-xr-xGradeBook_lib.tcl37
1 files changed, 36 insertions, 1 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl
index fce6e53..a31f05b 100755
--- a/GradeBook_lib.tcl
+++ b/GradeBook_lib.tcl
@@ -374,7 +374,42 @@ proc ResetForgottenPassword { permission_list user } {
}
#reset password procedure goes here
- htmlErrorMsg "Reset password is not fully implemented yet"
+ set newpassword [GenPassword]
+ UpdateColValue4UserNameNonWeb PasswordHash $user [::md5::md5 -hex $newpassword]
+ SendNewPassword2User $user $newpassword
+}
+
+proc GenPassword { } {
+ set password_chars "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ set len [string length $password_chars]
+
+ set i 1
+ set newpassword {}
+ while { $i <= 8 } {
+ incr i 1
+ set indx [expr {int(rand()*$len)}]
+ set newchar [string index $password_chars $indx]
+ append newpassword $newchar
+ }
+ return $newpassword
+}
+
+proc SendNewPassword2User { user password } {
+ set CourseTitle [SelectItemFromCourseInfoTable course_title]
+ set FirstName [SelectColValue4User FirstName $user]
+ set tmp_msg_file /tmp/tmp_msg4user_$user
+ set fp [open $tmp_msg_file w]
+ puts $fp "Dear ${FirstName},"
+ puts $fp "Your password to access $CourseTitle grades is"
+ puts $fp "------------------------------------------"
+ puts $fp "$password"
+ puts $fp "------------------------------------------"
+ close $fp
+ if { [catch {exec mail -s "New password for $CourseTitle" $user < $tmp_msg_file} msg ] } {
+ htmlErrorMsg "Something seems to have gone wrong during mailing the password. Information about it: $::errorInfo"
+ }
+ #now it is safe to delete temporary file
+ file delete $tmp_msg_file
}
proc LogMeOn {} {