Hide digits on postback with VB (e.g xxxxx6789)

reflo2

New member
Joined
Mar 15, 2013
Messages
1
Programming Experience
3-5
HI all

Sorry to butt into your forum but I have a quick problem that I have been goggleing but got no clear answer to, so hope someone can help.


Say I have a form with a text box and I used inputs 123456789, to this sent (via postback) to a 2nd form.
I would like this displayed on the second form with only the last 4 digits - the rest would be X's.

So 123456789 would look like this in the 2nd form xxxxx6789

A bit like you see with credit cards on many sites.

Can anyone ehlp ??

Thanks

Karen

Here is a little code of the 2 forms.



1st form

VB.NET:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<%@ Page Language="C#" %>
<html dir="ltr" xmlns="[url=http://www.w3.org/1999/xhtml]XHTML namespace[/url]">
<head runat="server">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
 <form id="form1" runat="server">
  <asp:TextBox runat="server" id="MyTextBox"></asp:TextBox>
  <asp:Button id="btnSubmit" PostBackUrl="form2.aspx" runat="server" Text="Press Me" />
 </form>
</body>
</html>

2nd form

VB.NET:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<html dir="ltr" xmlns="[url=http://www.w3.org/1999/xhtml]XHTML namespace[/url]">
<head runat="server">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<script runat="server" language="VB" type="text/vbscript"> 
 Dim strSomeValue
 Sub Page_Load() 
 
 strSomeValue = Request.Form("MyTextBox")
 My2ndTextBox.Text = strSomeValue 
End Sub 
</script>
</head>
<body>
 <form id="form1" runat="server">
 Value from 1st form = <asp:TextBox runat="server" id="My2ndTextBox"></asp:TextBox>
 </form>
</body>
</html>
 
In the second form:


My2ndTextBox.Text = New String("x", strSomeValue.Length - 4) & strSomeValue.Substring(strSomeValue.Length - 4, 4)
 
HI all

Sorry to butt into your forum but I have a quick problem that I have been goggleing but got no clear answer to, so hope someone can help.


Say I have a form with a text box and I used inputs 123456789, to this sent (via postback) to a 2nd form.
I would like this displayed on the second form with only the last 4 digits - the rest would be X's.

So 123456789 would look like this in the 2nd form xxxxx6789

A bit like you see with credit cards on many sites.

Can anyone ehlp ??

Thanks

Karen

Here is a little code of the 2 forms.



1st form

VB.NET:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<%@ Page Language="C#" %>
<html dir="ltr" xmlns="[url=http://www.w3.org/1999/xhtml]XHTML namespace[/url]">
<head runat="server">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
 <form id="form1" runat="server">
  <asp:TextBox runat="server" id="MyTextBox"></asp:TextBox>
  <asp:Button id="btnSubmit" PostBackUrl="form2.aspx" runat="server" Text="Press Me" />
 </form>
</body>
</html>

2nd form

VB.NET:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<html dir="ltr" xmlns="[url=http://www.w3.org/1999/xhtml]XHTML namespace[/url]">
<head runat="server">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<script runat="server" language="VB" type="text/vbscript"> 
 Dim strSomeValue
 Sub Page_Load() 
 
 strSomeValue = Request.Form("MyTextBox")
 My2ndTextBox.Text = strSomeValue 
End Sub 
</script>
</head>
<body>
 <form id="form1" runat="server">
 Value from 1st form = <asp:TextBox runat="server" id="My2ndTextBox"></asp:TextBox>
 </form>
</body>
</html>
You'll want to store the original number in a session variable, do not store it on the page itself anywhere, not even in a hidden element.
In the second form:


My2ndTextBox.Text = New String("x", strSomeValue.Length - 4) & strSomeValue.Substring(strSomeValue.Length - 4, 4)
One thing to check for is that the string is a length greater than 4, if it's 4 or less you'll get an exception with this code, otherwise this is exactly how I would accomplish the task.
 
I might add that if the only thing you are doing with the mystery string in the second form is showing it, you should export only the last 4 digits from the first form to prevent a "man in the middle" type of attack that someone might use to retrieve the full value during "transport".
 
Back
Top