Pay attention to the safety of the code

xiaoxiao2021-03-06  38

Topic: Safety of code

Yesterday I saw a post about Private, and now I have got the code below.

If you don't protect the code, you can reflect all the private variables of some classes through reflection.

In the program run, all variable values ​​can also be reflected.

I don't know what to feel. How to solve this problem simple and effectively?

Public Class Form1

Inherits System.Windows.Forms.form

Code generated by the Windows Form Designer

Private sub button1_click (byvale as system.object, byval e as system.eventargs) Handles Button1.click

Dim Mlogin As New LoginClass

Mlogin.isauth ("")

Dim myfieldInfo () as system.reflection.fieldInfo

Dim Pass as string

DIM mytype as type = mlogin.gettype

myfieldinfo = mytype.getfields (System.Reflection.BindingFlags.nonpublic OR _

System.Reflection.BindingFlags.instance or system.reflection.bindingflags.public)

DIM I as integer

For i = 0 to myfieldinfo.length - 1

IF myfieldinfo (i) .fieldType is gettype (string) THEN

Pass = myfieldInfo (i) .GetValue (mlogin) .tostring

mlogin.isauth (pass)

END IF

Next i

End Sub

END CLASS

Public Class loginclass

Private mpass string = "a # $ %% #% # 4545390rkdflssjrl% # (933234"

Public Function isauth (byval pass as string) as boolean

Try

IF pass = mpass life

Return True

Else

Return False

END IF

Finally

Mainlogin (isausth)

END TRY

END FUNCTION

Private Sub Mainlogin (byval isauth as boolean)

Dim mmain as new mainclass

Mmain.Pleaselogin (isaust)

End Sub

END CLASS

Public class mainclass

Public Sub Pleaselogin (Byval Isauth as Boolean)

IF isauth then

Msgbox ("Welcome Welcome, Warm Welcome")

Else

Msgbox ("Oh, please come again")

END IF

End Sub

END CLASS

转载请注明原文地址:https://www.9cbs.com/read-71483.html

New Post(0)