Hi,
im having a bad time trying to conditionally upsert the actual password to a new password if checkpwd from the actual password is true.
- if used as var and evaluate with val, checkpwd returns 0 or 1 instead of true or false (perhaps due to Convert(from Val, toID TypeID) not beeing called internally)
e.g.
{
users(func: has(password)) {
a as authenticated: checkpwd(password, "mySecret")
test: val(a)
}
}
returns (if password actually is “mySecret”), otherwise it return false and 0
{
"data": {
"users": [
{
"authenticated": true,
"test": 1
},
...
- already tried: if used with bool or string like
Cond: `@if(eq(val(a), true))`,
or
Cond: `@if(eq(val(a), "true"))`,
of course you will get a type error: rpc error: code = Unknown desc = : Invalid argment true. Comparing with different type
- if used in condition from upsert, the condition will always return false - so no mutation happens.
Cond: `@if(eq(val(a), 1)))`,
it does not matter, if the password is right, or you change the Condition to only mutate when the password is wrong…
Cond: `@if(eq(val(a), 0)))`,
the mutation is never fired.
- same thing if used checkpwd is used in a filter query (to test len of a in Condition):
passwordCondition(func: uid($uid)) @filter(eq(val(b), 1)) {
a as uid
b as checkpwd(password, $password)
}
How to use checkpwd in upsert / as variable in val?
(PS: i know i can split this into two transactions, but only one upsert call would be much more convenient, as this checkpwd is used on change email, change password and other more confidential methods…)