/**************************************************************
***************************************************************
**
** Host Application, Copyright (C) 2002-2004
** Ikanos Communication, Fremont, CA 
** All rights reserved.
**
** The information and contents of this file are the
** proprietary information of Ikanos Communication and may not
** be disclosed or used without the formal written approval of 
** Ikanos Communication
**
***************************************************************

$Revision: 1.1 $
$Date: 2006/10/16 04:34:50 $
**************************************************************/

/*******  Include Files         ***************************************/
#include <stdio.h>
#include <string.h>
#include "ipos.h"
#include "oampdb.h"
#include "consoleUtil.h"
#include "password.h"

/*******  Defines               ***************************************/
#define STATIC	static


/***********************************************************************
************************************************************************

          L O C A L    F U N C T I O N S

************************************************************************
***********************************************************************/

/*
************************************************************************
	Function: 
	
	Description: 
	
	Return Value: void
************************************************************************
*/
void changePassword(void)
{
  char newPassword[MAX_PASS_WD_LEN * 2];
  char oldPassword[MAX_PASS_WD_LEN * 2];
  char confirmPassword[MAX_PASS_WD_LEN * 2];
  
  consoleEchoDisable();
  printf ("\nEnter new password: ");
  scanf("%s",newPassword);
  printf ("\nConfirm new password: ");
  scanf("%s",confirmPassword);
  if (strcmp(newPassword,confirmPassword)!=0)
    printf ("\nError: passwords do not match");
  else
  {
    if (strlen(newPassword) > MAX_PASS_WD_LEN)
      printf ("\nError: password exceeds %d characters", MAX_PASS_WD_LEN);
    else
    {
      printf ("\nEnter old password: ");
      scanf("%s",oldPassword);
			if ((strcmp(newPassword, oampGetOperatorPassword) != 0) &&
          (strcmp(newPassword, oampGetSupervisorPassword) != 0))
			{
        if (strcmp(oldPassword, oampGetOperatorPassword) == 0)
        {
          oampSetOperatorPassword(newPassword);
          printf ("\nOperator Password Changed");
        }
        else
        {
          if (strcmp(oldPassword, oampGetSupervisorPassword) == 0)
          {
            oampSetSupervisorPassword(newPassword);
            printf ("\nSupervisor Password Changed");
          }
        }
			}
    }
  }
  consoleEchoEnable();
  return;
}

/*
************************************************************************
	Function: 
	
	Description: 
	
	Return Value: void
************************************************************************
*/
int verifyPassword(void)
{
  char Password[MAX_PASS_WD_LEN];
  int Rv;

  consoleEchoDisable();
  printf ("\nPlease enter console password:");
  scanf("%s",Password);
  consoleEchoEnable();

  if (strcmp(Password,oampGetSupervisorPassword) == 0)
    Rv = SUPERVISOR_MODE;
  else
  {
    if (strcmp(Password,oampGetOperatorPassword) == 0)
      Rv = OPERATOR_MODE;
    else
      Rv = INVALID_MODE;
  }

  return (Rv);
}

