A simple permission system based on logic operation (principle, design, implementation) VBS version _vbs

Source: Internet
Author: User
Tags logical operators
Author: slightboy
See a lot of students permission to judge is to use string and then or split or intercept

In fact, to allow/disallow (True/false) This kind of permission, the logical operation is more appropriate

Statement: This article is aimed at getting started and for the mastery of the students, if they already understand that can be ignored

Perhaps the meaning of the expression is not very clear, please forgive me.

Introduction to Logical operators:
And: Logic and

0 and 0 = 0
0 and 1 = 0
1 and 0 = 0
1 and 1 = 1
Or: Logical OR

0 Or 0 = 0
0 Or 1 = 1
1 Or 0 = 1
1 Or 1 = 1
XOR: Exclusive OR

0 Xor 0 = 0
0 Xor 1 = 1
1 Xor 0 = 1
1 Xor 1 = 0
Not: Logical non-

Not 1 = 0
Not 0 = 1


How to express:

1 means ture, 0 is False

Take two digits for example

The first digit represents the permission of Read, and the second represents the permission to Write, which can represent four permissions

Read (False) Write (false)
Read (True) Write (false)
Read (False) Write (true)
One Read (True) Write (True)


Operation Method Introduction:

Or continue with the above example

Read = (1), Write = 10 (2)

(0) and Read = 0
(1) and read = Read
Ten (2) and Read = 0
One (3) and read = Read
(0) and Write = 0
(1) and Write = 0
Ten (2) and write = Write
One (3) and write = Write


Here's how to show the sample code:

Permission definition class (to have an enumeration type) how nice ...)

Class PermissionType

Public Read
Public Write
Public Delete

Private Sub Class_Initialize
Read = 1
Write = 2
Delete = 4
End Sub

End Class
Permission class

Class permissionsetcomponent

Private Intvalue

Public Property Get Read ()
Read = GetValue (permission.read)
End Property

Public Property Let Read (Arg)
Call SetValue (Permission.read, Arg)
End Property

Public Property Get Write ()
Write = GetValue (permission.write)
End Property

Public Property Let Write (Arg)
Call SetValue (Permission.write, Arg)
End Property

Public Property Get Delete ()
Delete = GetValue (permission.delete)
End Property

Public Property Let Delete (Arg)
Call SetValue (Permission.delete, Arg)
End Property

Public Property Get Value ()
Value = Intvalue
End Property


Public Property Let Value (Arg)
Intvalue = arg
End Property

Public Function GetValue (inttype)
GetValue = (Value and inttype) = Inttype

End Function

Public Sub SetValue (inttype, Boolvalue)
IF (boolvalue) Then
Value = value Or inttype
Else
Value = value and (not inttype)
End IF
End Sub

End Class
Use sample code:

Dim Permission:set Permission = new PermissionType

Dim permissionset:set PermissionSet = new Permissionsetcomponent
Permissionset.value = 0
W ("Read:")
Permissionset.read = False
W (Permissionset.value & "" & Permissionset.read)

Permissionset.read = True
W (Permissionset.value & "" & Permissionset.read)

W ("Write:")
Permissionset.write = False
W (Permissionset.value & "" & Permissionset.write)

Permissionset.write = True
W (Permissionset.value & "" & Permissionset.write)

W ("Delete:")
Permissionset.delete = False
W (Permissionset.value & "" & Permissionset.delete)

Permissionset.delete = True
W (Permissionset.value & "" & Permissionset.delete)

Function W (o)
Response.Write ("<br/>" & O)
End Function


Today's lesson is here, we can extrapolate, class ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.