...
key with the contents of the password typed,
dir with the path of the problem type, and
computer_name with the name of host machine.
Note: It's like this Tcl procedure prototype: proc PasswordPath { key dir computer_name } { ... body... }
The script should return one of three possible codes:
0 in case of failure.
1 in case of success.
2 in case of success; the difference here is that the problem type has just saved the password information so GiD should not do it.
Furthermore, we can provide a description of the status returned for GiD to show to the user. If another status is returned, it is assumed to be 1 by default.
Below is an example of a <ValidatePassword> node. <ValidatePassword>
Code Block | ||
---|---|---|
| ||
<ValidatePassword> #validation.exe simulates an external program to validade the key for this computername |
...
#instead an external program can be used a tcl procedure |
...
if { [catch {set res [exec [file join $dir validation.exe] $key $computername]} msgerr] } { |
...
return [list 0 "Error $msgerr"] |
...
} |
...
switch -regexp – $res { |
...
failRB { |
...
return [list 0 "you ask me to fail!"] |
...
} |
...
okandsaveRB { |
...
proc save_pass {dir id pass} { |
...
set date [clock format [clock second] -format "%Y %m %d"] |
...
set fd [open [file join $dir .. "password.txt"] "a"] |
...
puts $fd "$id $pass # $date Password for Problem type '$dir'" |
...
close $fd |
...
} |
...
save_pass $dir $computername $key |
...
rename save_pass "" |
...
return [list 2 "password $key saved by me"] |
...
} |
...
okRB { |
...
return [list 1 "password $key will be saved by gid"] |
...
} |
...
default { |
...
return [list 0 "Error: unexpected return value $res"] |
...
} |
...
} |
...
</ValidatePassword> |