1f7215ac8SNathan Whitehorn /* crypt - simple encryption algorithm used for passwords
2f7215ac8SNathan Whitehorn **
3f7215ac8SNathan Whitehorn ** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
4f7215ac8SNathan Whitehorn */
5f7215ac8SNathan Whitehorn
6f7215ac8SNathan Whitehorn
7f7215ac8SNathan Whitehorn #include <Message.h>
8f7215ac8SNathan Whitehorn
9f7215ac8SNathan Whitehorn #include <string.h>
10f7215ac8SNathan Whitehorn #include <crypt.h>
11f7215ac8SNathan Whitehorn
12f7215ac8SNathan Whitehorn
13f7215ac8SNathan Whitehorn static const char key[PASSWORD_LENGTH + 1] = "Dr. Zoidberg Enterprises, BeMail";
14f7215ac8SNathan Whitehorn
15f7215ac8SNathan Whitehorn
get_passwd(const BMessage * msg,const char * name)16*1af4fa4bSClemens Zeidler _EXPORT char *get_passwd(const BMessage *msg,const char *name)
17f7215ac8SNathan Whitehorn {
18f7215ac8SNathan Whitehorn char *encryptedPassword;
19f7215ac8SNathan Whitehorn ssize_t length;
20f7215ac8SNathan Whitehorn if (msg->FindData(name,B_RAW_TYPE,(const void **)&encryptedPassword,&length) < B_OK || !encryptedPassword || length == 0)
21f7215ac8SNathan Whitehorn return NULL;
22f7215ac8SNathan Whitehorn
23f7215ac8SNathan Whitehorn char *buffer = new char[length];
24f7215ac8SNathan Whitehorn passwd_crypt(encryptedPassword,buffer,length);
25f7215ac8SNathan Whitehorn
26f7215ac8SNathan Whitehorn return buffer;
27f7215ac8SNathan Whitehorn }
28f7215ac8SNathan Whitehorn
29f7215ac8SNathan Whitehorn
set_passwd(BMessage * msg,const char * name,const char * password)30f7215ac8SNathan Whitehorn _EXPORT bool set_passwd(BMessage *msg,const char *name,const char *password)
31f7215ac8SNathan Whitehorn {
32f7215ac8SNathan Whitehorn if (!password)
33f7215ac8SNathan Whitehorn return false;
34f7215ac8SNathan Whitehorn
35f7215ac8SNathan Whitehorn ssize_t length = strlen(password) + 1;
36f7215ac8SNathan Whitehorn char *buffer = new char[length];
37f7215ac8SNathan Whitehorn passwd_crypt((char *)password,buffer,length);
38f7215ac8SNathan Whitehorn
39f7215ac8SNathan Whitehorn msg->RemoveName(name);
40f7215ac8SNathan Whitehorn status_t status = msg->AddData(name,B_RAW_TYPE,buffer,length,false);
41f7215ac8SNathan Whitehorn
42f7215ac8SNathan Whitehorn delete [] buffer;
43f7215ac8SNathan Whitehorn return (status >= B_OK);
44f7215ac8SNathan Whitehorn }
45f7215ac8SNathan Whitehorn
46f7215ac8SNathan Whitehorn
passwd_crypt(char * in,char * out,int length)47f7215ac8SNathan Whitehorn _EXPORT void passwd_crypt(char *in,char *out,int length)
48f7215ac8SNathan Whitehorn {
49f7215ac8SNathan Whitehorn int i;
50f7215ac8SNathan Whitehorn
51f7215ac8SNathan Whitehorn memcpy(out,in,length);
52f7215ac8SNathan Whitehorn if (length > PASSWORD_LENGTH)
53f7215ac8SNathan Whitehorn length = PASSWORD_LENGTH;
54f7215ac8SNathan Whitehorn
55f7215ac8SNathan Whitehorn for (i = 0;i < length;i++)
56f7215ac8SNathan Whitehorn out[i] ^= key[i];
57f7215ac8SNathan Whitehorn }
58f7215ac8SNathan Whitehorn
59