how to obfuscated with asterisks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sureshl
    New Member
    • Jan 2009
    • 23

    how to obfuscated with asterisks

    JavaScript Experts,

    I have the following HTML. How could I use JavaScript such that when a user clicks on the checkbox in each row the phone numbers and e-mail addresses are partially obfuscated with asterisks?

    Code:
    <table><tr><form method='post'><td>phone:</td><td>21323</td><td width='10%' align='right'>mail:</td><td>bob@example.com</td><input name='submit' type='submit' value='check'><input type='hidden' name='nameid' value='6' ></form></tr></table>
    Dis question is asked to forwarded to javascript ... By Nicodemas in above format...
    Am facing a problem, with this script...
    I want two fields to be written by star , in order to hide . and this script does it , but ,
    wat actually is my page opens directly with star letter , rather i need to open my page with the phoneno and email aftr clicking the button i want to make a change to the star to the respective fields ..........
    How can i do this...

    Page should open like ..
    21323
    dsad@dsa.com
    check (button) aftr clicking

    then
    213***
    ds**@*****

    Code:
    vbscript
     function getPhone(text)
     dim textsize
     textsize = Len(text)
     text = Left(text,5)
     For index = 0 to textsize
     text = text & "*"
     Next
     getphone = text
     End Function
     Function getEmail(text)
     dim textsize
     textsize =Len(text)
     dim atpos
     atpos = instr(text,"@") - 5
     text = Left(text,5)
     For index = 0 to textsize
     if atpos = index+1 then
     text = text & "@"
     else
     text = text & "*"
     end if
     Next
     getemail = text
     End Function
     Set oConn = Server.CreateObject("ADODB.Connection")
           Set oRs = Server.CreateObject("ADODB.Recordset")
           oConn.Open "Provider=SQLOLEDB; Data Source = ria; Initial Catalog = northwind; Integrated Security = sspi;"
      sSql =  "SELECT  phone,email,id FROM tbl1  userid =4 "
       oRs.Open sSql, oConn
          While not oRs.EOF
     Response.write("<table><tr><form method='post'><td >phone : </td><td>"&getPhone(ors(0))&"</td><td width='10%'align='right'mail :</td><td>"&getEmail(ors(1))&"</td><input name='submit' type='submit' value='check'><input type='hidden' name='nameid' value='" & ors(2) & "' ></form></tr></table>")
            oRs.MoveNext()
         Wend
         ors.close
         oconn.close
     if request.form("submit")="check" then
     i=1
     end if
     if  request.form("nameid") <> "" then
     set star1 = oConn.Execute("select resid from tbl1 where id= '" &request.form("nameid")&"'")
     if not star1.eof then
     sl = "UPDATE tbl1 SET star = '" & i & "' where resid= '" &request.form("nameid")&"' and userID = " & userid
     oConn.Execute sl
     End if
     End if
        %>
    Last edited by acoder; Jan 10 '09, 11:51 AM.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You'll need to use JavaScript rather than VBScript. Have you made a start on the JavaScript code?

    PS. the [code] tags have numbered lines - there's no need to add them manually.

    Comment

    • sureshl
      New Member
      • Jan 2009
      • 23

      #3
      yes i did ,with javascript

      But , i found one problem , that i couldn able to store the changes .

      I mean this eg shows , (done by javascriipt)

      Visualise this eg
      Page open like this..
      12332
      sdfdf@dsdfs.com
      Check (button) if clicked

      Changes to dis
      123****
      sdf**@*****


      But if i refresh the page,
      it again change to
      12332
      sdfdf@dsdfs.com

      so, am not able hold the obfuscated value , untill i change.....
      i need to hold the obfuscated value....thats y i tried server side....
      plz suggest..

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        So, initially you want it displayed, but as soon as it's replaced by asterisks, it should remain that way?

        If that's the case, you'll have to use server-side code. You can submit and change the database (or wherever the data is stored) so when you next refresh or display the page, the asterisks are there.

        If you want to avoid a reload of the page when replacing, you can use Ajax.

        Comment

        • sureshl
          New Member
          • Jan 2009
          • 23

          #5
          yes , Server Side or Ajax

          I dunno much about ajax . .

          how can i do this... as my script ensures to make a obfuscated values .

          but problem is , it directly opens directly with obfuscated values , i want to happen aftr clicking button , and have to be permanent untill i change...

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Should the "obfuscatio n" happen without reloading/unloading the page? If so, then Ajax it is, otherwise you only need server-side code. Let me know which it is.

            Comment

            • sureshl
              New Member
              • Jan 2009
              • 23

              #7
              ya .. If ajax is the solution..

              plz , U can tell me , how can i do it . .

              Coz i need to hold the value of those obfuscated details . so, that i can see the values when i loaded again .

              Thanks ...

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Here's a link to help get you started. Post back if you get stuck.

                Comment

                • sureshl
                  New Member
                  • Jan 2009
                  • 23

                  #9
                  Good one

                  This is what i understood, Am i right with these things..?

                  Yes . ajax is one which supports latest browsers where any functions can be called by javascript , and the functions status can be checked by readystate function , so whether the connection is success or not

                  So, aftr these steps, We have two options to do our need ,
                  Responsetext--> Some Text
                  Responsexml-->some xml documents travering by javascript functions..

                  Need some more clarity in Open, send ....

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    Originally posted by sureshl
                    Need some more clarity in Open, send ....
                    open() is comparable to the (HTML) form element, while send() is starting the http request (sending the variables)

                    see XMLHttpRequest – MDC

                    regards

                    Comment

                    • sureshl
                      New Member
                      • Jan 2009
                      • 23

                      #11
                      Clear now

                      This is my first ajax code...Okay , For my issue ,
                      I converted my vbscript to javascript , Is my coding is correct , Now i need to work such a way to convert my clear text to obfuscated values . .


                      Code:
                      function makeRequest(url) {
                              var httpRequest;
                      
                              if (window.XMLHttpRequest) { // Mozilla, Safari, ...
                                  httpRequest = new XMLHttpRequest();
                                  if (httpRequest.overrideMimeType) {
                                      httpRequest.overrideMimeType('text/xml');
                                      // See note below about this line
                                  }
                              } 
                              else if (window.ActiveXObject) { // IE
                                  try {
                                      httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                                  } 
                                  catch (e) {
                                      try {
                                          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                                      } 
                                      catch (e) {}
                                  }
                              }
                      
                              if (!httpRequest) {
                                  alert('Giving up :( Cannot create an XMLHTTP instance');
                                  return false;
                              }
                              httpRequest.onreadystatechange = function() { getphone(text); getemail(text); };
                              httpRequest.open('GET', url, true);
                              httpRequest.send('');
                      
                          }
                      
                          /*function alertContents(httpRequest) {
                      
                              if (httpRequest.readyState == 4) {
                                  if (httpRequest.status == 200) {
                                  <!--alert(httpRequest.responseText);-->
                                  } else {
                                      alert('There was a problem with the request.');
                                  }
                              }*/
                              function getPhone(text)
                                {
                                 if (httpRequest.readyState == 4)
                                  {
                                  if (httpRequest.status == 200) 
                                  {
                                    var textsize 
                                    textsize = Len(text)
                                    text = Left(text,5)
                                    For (index = 0 ;index <=textsize ; index++)
                                    {
                                    text = text & "*"
                                    }
                                    getphone = text
                                  }
                                  else 
                                  {
                                      alert('There was a problem with the request.');
                                  }
                                  }
                                  
                                  function getEmail(text)
                                  {
                                  if (httpRequest.readyState == 4)
                                  {
                                  if (httpRequest.status == 200) 
                                  {
                                  var textsize
                                  textsize =Len(text)
                                  var atpos
                                  atpos = instr(text,"@") - 5
                                  text = Left(text,5)
                                  for(index = 0 ; index<=textsize ; index ++ )
                                  {
                                  if atpos = index+1 then
                                  text = text & "@"
                                  }
                                  else
                                  {
                                  text = text & "*"
                                  }
                                  }
                                  getemail = text
                                  }
                                  </script>
                      If the above code is correct , how can i call this ajax script in my code ,

                      Code:
                      Set oConn = Server.CreateObject("ADODB.Connection")
                              Set oRs = Server.CreateObject("ADODB.Recordset")
                              oConn.Open "Provider=SQLOLEDB; Data Source = ria; Initial Catalog = northwind; Integrated Security = sspi;"
                         sSql =  "SELECT  phone,email,id FROM tbl1  userid =4 "
                          oRs.Open sSql, oConn
                             While not oRs.EOF
                        Response.write("<table><tr><form method='post'><td >phone : </td><td>"&getPhone(ors(0))&"</td><td width='10%'align='right'mail :</td><td>"&getEmail(ors(1))&"</td><input name='submit' type='submit' value='check'><input type='hidden' name='nameid' value='" & ors(2) & "' ></form></tr></table>")
                               oRs.MoveNext()
                            Wend
                            ors.close
                            oconn.close

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Before we go any further, the only benefit Ajax would provide here is that the "obfuscatio n" would take place almost instantly without having to submit a form and unloading the page. If that's not important, Ajax is not necessary and you can simply submit the form to a server-side page (code you already have) and display the values with parts replaced by asterisks.

                        Comment

                        • sureshl
                          New Member
                          • Jan 2009
                          • 23

                          #13
                          yes , server side is enough ..but how..

                          Now my present code and Problem i had explained....
                          my below retreives only first data...i mean only this...
                          12343 dsf@sd.ds ,
                          i want to retrieve all the data, for those uservalue has id =1

                          My db :
                          tbluser
                          uservalue id
                          2 1
                          3 1
                          4 1
                          5 1
                          and using this uservalue it rerieves phone, email from this table
                          tblstudent
                          phone email uservalue
                          12343 dsf@sd.ds 2
                          123231 dsf@ds.df 3
                          123231 sfd@dfs.ds 4

                          Code:
                          set chk =oConn.execute("select uservalue from tbluser where id = 1")  
                            if not chk.EOF then
                             id  =chk("uservalue")
                              sSql =  "SELECT  phoneno,email,id FROM tblstudent where  uservalue = " & id 
                              oRs.Open sSql, oConn
                                 While not oRs.EOF 
                                 Response.write("<table><tr><form method='post'><td >phone : </td><td>" & getphone(ors(0)) & "</td><td width='10%'align='right'mail :</td><td>"& getEmail(ors(1)) &"</td><input name='submit' type='submit'  value='check'><input type='hidden'  name='nameid' value='" & ors(2) & "' ></form></tr></table>")
                                 oRs.MoveNext()
                              Wend
                          end if
                            if request.form("submit")="check" then
                            i=1
                            end if
                            if  request.form("nameid") <> "" then
                            set star1 = oConn.Execute("select resid from tbl1 where id= '" &request.form("nameid")&"'")
                            if not star1.eof then
                            sl = "UPDATE tbl1 SET star = '" & i & "' where resid= '" &request.form("nameid")&"' and userID = " & userid
                            oConn.Execute sl
                            End if
                            End if

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            Your best bet for that would be the ASP forum. If you do decide to grapple with Ajax again, you can come back to this thread.

                            Comment

                            Working...