Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data / System / Data / SqlClient / SqlCredential.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="SqlCredential.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
8
9 namespace System.Data.SqlClient
10 {
11     using System;
12     using System.Security;
13     using System.Data.Common;
14
15     // Represent a pair of user id and password which to be used for SQL Authentication
16     // SqlCredential takes password as SecureString which is better way to store security sensitive information
17     // This class is immutable
18     public sealed class SqlCredential
19     {
20         string _userId;
21         SecureString _password;
22
23         //
24         // PUBLIC CONSTRUCTOR
25         //
26
27         // SqlCredential
28         //  userId: userId
29         //  password: password
30         //
31         public SqlCredential(string userId, SecureString password)
32         {
33             if (userId == null)
34             {
35                 throw ADP.ArgumentNull("userId");
36             }
37
38             if (userId.Length > TdsEnums.MAXLEN_USERNAME)
39             {
40                 throw ADP.InvalidArgumentLength("userId", TdsEnums.MAXLEN_USERNAME);
41             }
42
43             if (password == null)
44             {
45                 throw ADP.ArgumentNull("password");
46             }
47
48             if (password.Length > TdsEnums.MAXLEN_PASSWORD)
49             {
50                 throw ADP.InvalidArgumentLength("password", TdsEnums.MAXLEN_PASSWORD);
51             }
52
53             if (!password.IsReadOnly())
54             {
55                 throw ADP.MustBeReadOnly("password");
56             }
57
58             _userId = userId;
59             _password = password;
60         }
61
62         //
63         // PUBLIC PROPERTIES
64         //
65         public string UserId
66         {
67             get
68             {
69                 return _userId;
70             }
71         }
72
73         public SecureString Password
74         {
75             get
76             {
77                 return _password;
78             }
79         }
80     }
81 }   // System.Data.SqlClient namespace
82
83