Comparing two strings

hi experts

I have the following code to compare two string
in fact i have two strings stored in the db
one is encrypted, the other is not encrypted

i am comparing decrypted value of the encrypted one with the other string and display a message accordingly

Sub ValidateCoupon (rc, msg)
dim EncodedName, DecodedName, Realname
EncodedName=couponname
DecodedName= Base64decode(EncodedName)
Realname = couponother

response.write "realname = <br>" & DecodedName & "<br>"
response.write "couponother = <br>" & Realname

if ucase(DecodedName) <> ucase(Realname) then
     msg= "Bad coupon name"
     rc=4
     exit sub
end if
end sub

OK now my problem it that when i compare decodedname and realname,
i get the result  "Bad coupon name" even if they are equal

My response.write shows that decodedname and realname are the same.

What the problem ?
Thx


LVL 1
humer2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alorentzCommented:
Do this:

<%
response.write "realname = <br>|" & DecodedName & "|<br>"
response.write "couponother = <br>|" & Realname & "|<br>
%>

I'm guessing there's some blank spaces in there
0
alorentzCommented:
Also try this:

<%
if ucase(trim(DecodedName)) <> ucase(trim(Realname)) then
     msg= "Bad coupon name"
     rc=4
     exit sub
end if
%>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alorentzCommented:
Could also do this:

<%
if ucase(left(DecodedName, len(realname))) <> ucase(Realname) then
     msg= "Bad coupon name"
     rc=4
     exit sub
end if
%>

Maybe return carriage or line feed on end of decode name, so just take the length of the realname and compare.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

calvinfooCommented:
Hi,

 try this:

  if ucase(trim(DecodedName)) <> ucase(trim(Realname)) then
     msg= "Bad coupon name"
     rc=4
     exit sub
end if
0
calvinfooCommented:
ops, sorry, I guess I've repeated what alorentz said.
0
Sukamal_SenguptaCommented:
Hi humer2000,

Hope the string that you get after decrypte the string (which is store in the db) is done correctly means there is no any hidden word or space included into that string, which is not shown in the browser.
 
Try the following code which is slightly modified from your code,

Sub ValidateCoupon (rc, msg)
    dim EncodedName, DecodedName, Realname
    EncodedName=couponname
    DecodedName= Base64decode(EncodedName)
    Realname = couponother

   DecodedName = Trim(cstr(DecodedName))
   Realname = Trim(cstr(Realname ))

   response.write "DecodedName = <br>" & DecodedName & "<br>"
   response.write "Realname = <br>" & Realname

  if ((cstr(DecodedName)) <>(cstr(Realname))) then
     msg= "Bad coupon name"
     rc=4
     exit sub
  end if

end sub


Hope you don't use the procedure i.e., ValidateCoupon within any loop.

Try the Modified code. Hope your problem will be solved.

Thanks,
Sukamal Sengupta


 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.