Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. /**************************************************************************
  2. * *
  3. * File: DocumentManager.cs *
  4. * Copyright: (c) 2008-2010, Florin Leon *
  5. * E-mail: fleon@cs.tuiasi.ro *
  6. * Website: http://florinleon.byethost24.com/lab_ip.htm *
  7. * Description: Secret documents application with Protection Proxy. *
  8. * The Protection Proxy (Software Engineering lab 9) *
  9. * *
  10. * This code and information is provided "as is" without warranty of *
  11. * any kind, either expressed or implied, including but not limited *
  12. * to the implied warranties of merchantability or fitness for a *
  13. * particular purpose. You are free to use this source code in your *
  14. * applications as long as the original copyright notice is included. *
  15. * *
  16. **************************************************************************/
  17.  
  18. using System;
  19. using System.Collections.Generic;
  20. using System.IO;
  21. using static ProtectionProxy.ProxyDocumentManager;
  22.  
  23. namespace ProtectionProxy
  24. {
  25. public class ProxyDocumentManager : IDocumentManager
  26. {
  27. private RealDocumentManager _realDocumentManager;
  28. private List<User> _users;
  29. private List<string> _levels;
  30. private const string Path = "Secure\\";
  31.  
  32. public struct User
  33. {
  34. public readonly string Name;
  35. public readonly string PassHash;
  36. public readonly int AccessLevel;
  37.  
  38. public User(string name, string passHash, int accessLevel)
  39. {
  40. Name = name;
  41. PassHash = passHash;
  42. AccessLevel = accessLevel;
  43. }
  44. }
  45.  
  46. public ProxyDocumentManager()
  47. {
  48. _levels = new List<string>();
  49. StreamReader sr = new StreamReader(Path + "niveluri.txt");
  50. string[] lvls = sr.ReadToEnd().Split(" \t\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  51. sr.Close();
  52.  
  53. for (int i = 0; i < lvls.Length; i++)
  54. _levels.Add(lvls[i]);
  55.  
  56. _users = new List<User>();
  57. sr = new StreamReader(Path + "utilizatori.txt");
  58. while (sr.Peek() != -1)
  59. {
  60. string[] toks = sr.ReadLine().Split('\t');
  61. User user = new User(toks[0], toks[1], Convert.ToInt32(toks[2]));
  62. _users.Add(user);
  63. }
  64. sr.Close();
  65. }
  66.  
  67. #region IDocumentManager Members
  68. public bool Login(string username,string password)
  69. {
  70. bool ok = false;
  71. string hashPass = Cryptography.HashString(password);
  72. foreach(User u in _users)
  73. {
  74. if(u.Name==username && u.PassHash==hashPass)
  75. {
  76. ok = true;
  77. _realDocumentManager = new RealDocumentManager(u.AccessLevel);
  78. }
  79. }
  80. return ok;
  81. }
  82.  
  83. public List<string> GetDocumentList()
  84. {
  85.  
  86. }
  87.  
  88.  
  89. public string GetDocument(string documentName, string encryptionPassword)
  90. {
  91. string encrypt = _realDocumentManager.GetDocument(documentName, encryptionPassword);
  92. string decript = Cryptography.Decrypt(encrypt, encryptionPassword);
  93. return decript;
  94. }
  95.  
  96. #endregion IDocumentManager Members
  97. }
  98.  
  99.  
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement