Search code examples
asp.netvb.netdata-masking

Data Masking in asp.net


i want to display confidential data like bank account number, mobile numbers in 123**********1232 format in ASP.net controls. Like 022-23232-2322 will be 022*********2322 and on update it should save the actual data entered.

How it would be achieved in ASP.net?


Solution

  • If you want to mask it only for users which can't update it as commented, it's simple:

    Dim number = "022-23232-2322" 
    Dim token = number.split("-"c)
    Dim masked = String.Format("{0}{1}{2}", token(0), New String("*"c, 9), token.last())
    

    Result as dersired: 022*********2322

    Of course you have to store the real number serverside or load it from database when you need it. You should never need to unmask it. If an authorized user wants to update it you get the new value and you don't need the old. If you need it reload it from the data-source.