SqlCredential.cs 2.2 KB

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