#!/usr/bin/tclsh
#
# This file is part of Helga.
#
# Helga 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 3 of the License, or
# (at your option) any later version.
#
# Helga 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 Helga. If not, see .
#
if { $argc != 3 } {
puts "Usage: hpasswd.tclsh "
exit 1
}
set user [lindex $argv 0]
set oldPass [lindex $argv 1]
set newPass [lindex $argv 2]
package require mysqltcl
set dirName [file dirname [file normalize $argv0]]
source "$dirName/sourceConf.tcl"
if { [catch "::mysql::connect -user helgaAdmin -password $::ADMINSQLPASS -db $::SQLDB" db] } {
error "Error: hpasswd.tclsh: mysql::connect: $db"
}
# make sure the old pass is correct
set sql "SELECT a.`assetId` FROM `users` u, `assets` a WHERE a.`assetName` = '$user' AND a.`assetId` = u.`assetId` AND u.`password` = '$oldPass'"
set result [::mysql::sel $db $sql -list]
if { $result == "" } {
error "Error: incorrect password"
}
# then do a sql update
set userId [lindex [lindex $result 0] 0]
set sql "UPDATE `users` SET `password` = '$newPass' WHERE `assetId` = $userId"
::mysql::exec $db $sql