[REBOL] Re: Help!
From: al:bri:xtra at: 23-Oct-2000 23:01
Sharriff wrote:
> Here is a simplified snippet of a sort of user validation that I´m
coding:
> challenge: make object! [ log-name: "sharriff" password: "gong" ]
> temp-logname: to-word challenge/log-name
> temp-password: challenge/password
> validname: select temp-db temp-logname
> validpass: find temp-db temp-password
> either found? validname [either found? validpass [print "go"][print
> "nogo"]] [ print "wrong password"]
>
> The problem is, the outer "Either" never evalutes if "validname" is true,
can someone tell me what I´ve overlooked?
I'd be reluctant to do this:
> temp-logname: to-word challenge/log-name
what if challenge/log-name _isn't_ valid Rebol word? Like:
Andrew.1
Also, for this line:
validpass: find temp-db temp-password
I think you might mean:
validpass: find temp-db VALIDNAME
but I'm uncertain of your intent.
Have you thought about using an Associative array? Then, for putting
passwords in, you could write:
Associate Passwords-Block "sharriff" "gong"
Associate Passwords-Block "Andrew.1" "%#2"
Then you could retrieve the passwords by writing:
Associate? Passwords-Block "Andrew.1"
== "%#2"
Associate? Passwords-Block ask "What's your User name:" ask "What's
your Password:"
and you could check for bad passwords, like this:
Associate? Passwords-Block "J. Random Hacker"
== none
I thought this approach would be a lot cleaner. The code for Associate and
Associate? is below my .sig. I hope that helps!
Andrew Martin
ICQ: 26227169
http://members.nbci.com/AndrewMartin/
-><-
[
Associate!: make object! [
Find: function [Block [block!] Key] [Index] [
Index: Block
until [
Index: system/words/find/only Index Key
if not found? Index [return none]
either odd? offset? Block Index [
Index: next Index
false
][
true
]
]
Index
]
set 'Associate? function [Block [block!] Key] [Index] [
either found? Index: Find Block Key [
first second Index
][
none
]
]
set 'Associate function [Block [block!] Key Value] [Index] [
Index: Find Block Key
either none? Value [
if found? Index [
remove/part Index 2
]
][
Value: reduce [Value]
either found? Index [
change/only next Index Value
][
append Block reduce [Key Value]
]
]
Block
]
]
]