diff options
-rwxr-xr-x | GradeBook_lib.tcl | 37 |
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 {} { |