#by wiebe @ QuakeNet



#help newpass msg
bind msgm -|- "help newpass" c_newpass:help:msg

proc c_newpass:help:msg { nick uhost handle text } {
  lappend output "Usage: newpass <oldpassword> <newpassword> <newpassword>"
  lappend output "Changes your password, the new password must be at least 6 chars long."
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putcmdlog "($nick!$uhost) !$handle! $text"
}



#newpass msg
bind msg -|- newpass c_newpass:msg

proc c_newpass:msg { nick uhost handle text } {
  if { [string equal $handle *] } { return 0 }
  if { [matchattr $handle k] } { return 0 }
  set oldpass [lindex [split $text] 0]
  set newpass1 [lindex [split $text] 1]
  set newpass2 [lindex [split $text] 2]
  if { [passwdok $handle -] } {
    set pass [string range [md5 [rand 999999999]] 0 6]
    lappend output "Your password has been set to $pass, You must change it at once!"
    lappend output "/msg $::botnick newpass $pass <newpassword> <new\017password>"
    lappend output "The new password must be at least 6 chars long. Mixing lower & upper case letters, digits and special chars."
    setuser $handle PASS $pass
  } elseif { [string equal $newpass2 ""] } {
    lappend output "Usage: newpass <oldpassword> <newpassword> <new\017password>"
  } elseif { ![passwdok $handle $oldpass] } {
    lappend output "Password incorrect."
  } elseif { ![string equal $newpass1 $newpass2] } {
    lappend output "The new passwords do not match."
    lappend output "Usage: newpass <oldpassword> <newpassword> <new\017password>"   
  } else {
    setuser $handle PASS $newpass1
    lappend output "Ok, password has been changed."
  }
  if { [catch {set x [cnotice $nick $output]} error] || !$x } {
    foreach t $output { puthelp "NOTICE $nick :$t" }
  }
  putcmdlog "($nick!$uhost) !$handle! newpass .."
}

