Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 410
  • Last Modified:

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


0
humer2000
Asked:
humer2000
  • 3
  • 2
1 Solution
 
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now