encrypt.c

smug/encrypt.c · 579 B

From the archive smug-r8.tar.gz

Download the archive   « Back to the archive contents

/* Copyright 1989, 1990 by James Aspnes, David Applegate, and Bennet Yee */
/* See the file COPYING for distribution information */
#include "os.h"
#include "db.h"

const char *alphabet =
  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";

const char *encrypt_password (const char *password)
{
  char salt[3];

  salt[0] = alphabet[RAND () % 64];
  salt[1] = alphabet[RAND () % 64];
  salt[2] = '\0';

  return crypt (password, salt);
}

int check_password (const char *clear, const char *encrypted)
{
  return !strcmp (encrypted, crypt (clear, encrypted));
}

Site Stats

Snippets: 1791
Codebases: 571