Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************************
- * *
- * File: DocumentManager.cs *
- * Copyright: (c) 2008-2010, Florin Leon *
- * E-mail: fleon@cs.tuiasi.ro *
- * Website: http://florinleon.byethost24.com/lab_ip.htm *
- * Description: Secret documents application with Protection Proxy. *
- * The Protection Proxy (Software Engineering lab 9) *
- * *
- * This code and information is provided "as is" without warranty of *
- * any kind, either expressed or implied, including but not limited *
- * to the implied warranties of merchantability or fitness for a *
- * particular purpose. You are free to use this source code in your *
- * applications as long as the original copyright notice is included. *
- * *
- **************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.IO;
- using static ProtectionProxy.ProxyDocumentManager;
- namespace ProtectionProxy
- {
- public class ProxyDocumentManager : IDocumentManager
- {
- private RealDocumentManager _realDocumentManager;
- private List<User> _users;
- private List<string> _levels;
- private const string Path = "Secure\\";
- public struct User
- {
- public readonly string Name;
- public readonly string PassHash;
- public readonly int AccessLevel;
- public User(string name, string passHash, int accessLevel)
- {
- Name = name;
- PassHash = passHash;
- AccessLevel = accessLevel;
- }
- }
- public ProxyDocumentManager()
- {
- _levels = new List<string>();
- StreamReader sr = new StreamReader(Path + "niveluri.txt");
- string[] lvls = sr.ReadToEnd().Split(" \t\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- sr.Close();
- for (int i = 0; i < lvls.Length; i++)
- _levels.Add(lvls[i]);
- _users = new List<User>();
- sr = new StreamReader(Path + "utilizatori.txt");
- while (sr.Peek() != -1)
- {
- string[] toks = sr.ReadLine().Split('\t');
- User user = new User(toks[0], toks[1], Convert.ToInt32(toks[2]));
- _users.Add(user);
- }
- sr.Close();
- }
- #region IDocumentManager Members
- public bool Login(string username,string password)
- {
- bool ok = false;
- string hashPass = Cryptography.HashString(password);
- foreach(User u in _users)
- {
- if(u.Name==username && u.PassHash==hashPass)
- {
- ok = true;
- _realDocumentManager = new RealDocumentManager(u.AccessLevel);
- }
- }
- return ok;
- }
- public List<string> GetDocumentList()
- {
- }
- public string GetDocument(string documentName, string encryptionPassword)
- {
- string encrypt = _realDocumentManager.GetDocument(documentName, encryptionPassword);
- string decript = Cryptography.Decrypt(encrypt, encryptionPassword);
- return decript;
- }
- #endregion IDocumentManager Members
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement