2 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Bumjin Im <bj.im@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
19 * @file password-file.h
20 * @author Zbigniew Jasinski (z.jasinski@samsung.com)
21 * @author Lukasz Kostyra (l.kostyra@partner.samsung.com)
23 * @brief Implementation of PasswordFile, used to manage password files.
25 #ifndef _PASSWORD_FILE_H_
26 #define _PASSWORD_FILE_H_
35 #include <dpl/serialization.h>
37 namespace SecurityServer
44 void writeMemoryToFile() const;
45 void writeAttemptToFile() const;
47 void setPassword(const std::string &password);
48 bool checkPassword(const std::string &password) const;
49 bool isPasswordActive() const;
51 void setHistory(unsigned int history);
52 unsigned int getHistorySize() const;
54 time_t getExpireTime() const;
55 time_t getExpireTimeLeft() const;
56 void setExpireTime(int expireTime);
58 //attempt manipulating functions
59 unsigned int getAttempt() const;
61 void incrementAttempt();
62 int getMaxAttempt() const;
63 void setMaxAttempt(unsigned int maxAttempt);
65 bool isPasswordReused(const std::string &password) const;
67 bool checkExpiration() const;
68 bool isIgnorePeriod() const;
71 typedef std::vector<unsigned char> RawHash;
72 typedef std::chrono::duration<double> TimeDiff;
73 typedef std::chrono::time_point<std::chrono::monotonic_clock, TimeDiff> TimePoint;
75 struct Password: public ISerializable
78 Password(const RawHash& password);
79 Password(IStream& stream);
81 virtual void Serialize(IStream &stream) const;
86 typedef std::list<Password> PasswordList;
88 void loadMemoryFromFile();
91 void preparePwdFile();
92 void prepareAttemptFile();
93 bool fileExists(const std::string &filename) const;
94 bool dirExists(const std::string &dirpath) const;
95 static RawHash hashPassword(const std::string &password);
97 mutable TimePoint m_retryTimerStart;
100 PasswordList m_passwords;
101 unsigned int m_maxAttempt;
102 unsigned int m_historySize;
106 unsigned int m_attempt;
108 } //namespace SecurityServer